Skip to content

Package updates #1146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
"isRoot": true,
"tools": {
"jetbrains.resharper.globaltools": {
"version": "2021.3.0",
"version": "2021.3.4",
"commands": [
"jb"
]
},
"regitlint": {
"version": "6.0.6",
"version": "6.0.8",
"commands": [
"regitlint"
]
Expand All @@ -21,7 +21,7 @@
]
},
"dotnet-reportgenerator-globaltool": {
"version": "5.0.0",
"version": "5.1.3",
"commands": [
"reportgenerator"
]
Expand Down
3 changes: 2 additions & 1 deletion CodingGuidelines.ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
<Rule Id="AV1555" Action="Warning" />
<Rule Id="AV1564" Action="Info" />
<Rule Id="AV1568" Action="Warning" />
<Rule Id="AV1580" Action="None" />
<Rule Id="AV1706" Action="Warning" />
<Rule Id="AV1710" Action="Info" />
<Rule Id="AV1711" Action="Info" />
<Rule Id="AV1738" Action="Warning" />
<Rule Id="AV1739" Action="Warning" />
<Rule Id="AV1745" Action="Warning" />
<Rule Id="AV1755" Action="Warning" />
<Rule Id="AV2210" Action="None" />
<Rule Id="AV2210" Action="Warning" />
<Rule Id="AV2220" Action="Warning" />
<Rule Id="AV2230" Action="Info" />
<Rule Id="AV2305" Action="None" />
Expand Down
10 changes: 7 additions & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<AspNetVersion>6.0.*</AspNetVersion>
<EFCoreVersion>6.0.*</EFCoreVersion>
<EFCorePostgresVersion>6.0.*</EFCorePostgresVersion>
<MicrosoftCodeAnalysisVersion>4.0.*</MicrosoftCodeAnalysisVersion>
<MicrosoftCodeAnalysisVersion>4.1.*</MicrosoftCodeAnalysisVersion>
<HumanizerVersion>2.*</HumanizerVersion>
<JsonApiDotNetCoreVersionPrefix>5.0.0</JsonApiDotNetCoreVersionPrefix>
<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)CodingGuidelines.ruleset</CodeAnalysisRuleSet>
Expand All @@ -17,7 +17,7 @@

<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2021.3.0" PrivateAssets="All" />
<PackageReference Include="CSharpGuidelinesAnalyzer" Version="3.7.1" PrivateAssets="All" />
<PackageReference Include="CSharpGuidelinesAnalyzer" Version="3.8.0" PrivateAssets="All" />
<AdditionalFiles Include="$(MSBuildThisFileDirectory)CSharpGuidelinesAnalyzer.config" Visible="False" />
</ItemGroup>

Expand All @@ -27,10 +27,14 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Debug'">
<NoWarn>$(NoWarn);AV2210</NoWarn>
</PropertyGroup>

<!-- Test Project Dependencies -->
<PropertyGroup>
<CoverletVersion>3.1.2</CoverletVersion>
<MoqVersion>4.16.1</MoqVersion>
<MoqVersion>4.17.2</MoqVersion>
<TestSdkVersion>17.1.0</TestSdkVersion>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion benchmarks/Serialization/SerializationBenchmarkBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public RelationshipLinks GetRelationshipLinks(RelationshipAttribute relationship

private sealed class FakeMetaBuilder : IMetaBuilder
{
public void Add(IReadOnlyDictionary<string, object?> values)
public void Add(IDictionary<string, object?> values)
{
}

Expand Down
15 changes: 13 additions & 2 deletions src/JsonApiDotNetCore.Annotations/ArgumentGuard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,24 @@ public static void NotNull<T>([NoEnumeration] [SysNotNull] T? value, [InvokerPar
}

[AssertionMethod]
public static void NotNullNorEmpty<T>([SysNotNull] IEnumerable<T>? value, [InvokerParameterName] string name, string? collectionName = null)
public static void NotNullNorEmpty<T>([SysNotNull] IEnumerable<T>? value, [InvokerParameterName] string name)
{
NotNull(value, name);

if (!value.Any())
{
throw new ArgumentException($"Must have one or more {collectionName ?? name}.", name);
throw new ArgumentException($"Must have one or more {name}.", name);
}
}

[AssertionMethod]
public static void NotNullNorEmpty<T>([SysNotNull] IEnumerable<T>? value, [InvokerParameterName] string name, string collectionName)
{
NotNull(value, name);

if (!value.Any())
{
throw new ArgumentException($"Must have one or more {collectionName}.", name);
}
}

Expand Down
14 changes: 12 additions & 2 deletions src/JsonApiDotNetCore.Annotations/CollectionConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,19 @@ private Type ToConcreteCollectionType(Type collectionType)
/// <summary>
/// Returns a collection that contains zero, one or multiple resources, depending on the specified value.
/// </summary>
public ICollection<IIdentifiable> ExtractResources(object? value)
public IReadOnlyCollection<IIdentifiable> ExtractResources(object? value)
{
if (value is ICollection<IIdentifiable> resourceCollection)
if (value is List<IIdentifiable> resourceList)
{
return resourceList;
}

if (value is HashSet<IIdentifiable> resourceSet)
{
return resourceSet;
}

if (value is IReadOnlyCollection<IIdentifiable> resourceCollection)
{
return resourceCollection;
}
Expand Down
10 changes: 8 additions & 2 deletions src/JsonApiDotNetCore.Annotations/Configuration/ResourceType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,14 @@ public sealed class ResourceType
/// </remarks>
public LinkTypes RelationshipLinks { get; }

public ResourceType(string publicName, Type clrType, Type identityClrType, IReadOnlyCollection<AttrAttribute>? attributes = null,
IReadOnlyCollection<RelationshipAttribute>? relationships = null, IReadOnlyCollection<EagerLoadAttribute>? eagerLoads = null,
public ResourceType(string publicName, Type clrType, Type identityClrType, LinkTypes topLevelLinks = LinkTypes.NotConfigured,
LinkTypes resourceLinks = LinkTypes.NotConfigured, LinkTypes relationshipLinks = LinkTypes.NotConfigured)
: this(publicName, clrType, identityClrType, null, null, null, topLevelLinks, resourceLinks, relationshipLinks)
{
}

public ResourceType(string publicName, Type clrType, Type identityClrType, IReadOnlyCollection<AttrAttribute>? attributes,
IReadOnlyCollection<RelationshipAttribute>? relationships, IReadOnlyCollection<EagerLoadAttribute>? eagerLoads,
LinkTypes topLevelLinks = LinkTypes.NotConfigured, LinkTypes resourceLinks = LinkTypes.NotConfigured,
LinkTypes relationshipLinks = LinkTypes.NotConfigured)
{
Expand Down
2 changes: 1 addition & 1 deletion src/JsonApiDotNetCore.Annotations/ObjectExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma warning disable AV1130 // Return type in method signature should be a collection interface instead of a concrete type
#pragma warning disable AV1130 // Return type in method signature should be an interface to an unchangeable collection

namespace JsonApiDotNetCore;

Expand Down
2 changes: 1 addition & 1 deletion src/JsonApiDotNetCore/ArrayFactory.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma warning disable AV1008 // Class should not be static
#pragma warning disable AV1130 // Return type in method signature should be a collection interface instead of a concrete type
#pragma warning disable AV1130 // Return type in method signature should be an interface to an unchangeable collection

namespace JsonApiDotNetCore;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public SetRelationshipProcessor(ISetRelationshipService<TResource, TId> service)

if (relationship is HasManyAttribute)
{
ICollection<IIdentifiable> rightResources = _collectionConverter.ExtractResources(rightValue);
IReadOnlyCollection<IIdentifiable> rightResources = _collectionConverter.ExtractResources(rightValue);
return rightResources.ToHashSet(IdentifiableComparer.Instance);
}

Expand Down
4 changes: 4 additions & 0 deletions src/JsonApiDotNetCore/Configuration/ResourceGraphBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,10 @@ private static bool IsImplicitManyToManyJoinEntity(IEntityType entityType)
/// The name under which the resource is publicly exposed by the API. If nothing is specified, the naming convention is applied on the pluralized CLR
/// type name.
/// </param>
#pragma warning disable AV1553 // Do not use optional parameters with default value null for strings, collections or tasks
public ResourceGraphBuilder Add<TResource, TId>(string? publicName = null)
where TResource : class, IIdentifiable<TId>
#pragma warning restore AV1553 // Do not use optional parameters with default value null for strings, collections or tasks
{
return Add(typeof(TResource), typeof(TId), publicName);
}
Expand All @@ -194,7 +196,9 @@ public ResourceGraphBuilder Add<TResource, TId>(string? publicName = null)
/// The name under which the resource is publicly exposed by the API. If nothing is specified, the naming convention is applied on the pluralized CLR
/// type name.
/// </param>
#pragma warning disable AV1553 // Do not use optional parameters with default value null for strings, collections or tasks
public ResourceGraphBuilder Add(Type resourceClrType, Type? idClrType = null, string? publicName = null)
#pragma warning restore AV1553 // Do not use optional parameters with default value null for strings, collections or tasks
{
ArgumentGuard.NotNull(resourceClrType, nameof(resourceClrType));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;

#pragma warning disable AV1130 // Return type in method signature should be an interface to an unchangeable collection

namespace JsonApiDotNetCore.Configuration;

[PublicAPI]
Expand All @@ -16,9 +18,11 @@ public static class ServiceCollectionExtensions
/// <summary>
/// Configures JsonApiDotNetCore by registering resources manually.
/// </summary>
#pragma warning disable AV1553 // Do not use optional parameters with default value null for strings, collections or tasks
public static IServiceCollection AddJsonApi(this IServiceCollection services, Action<JsonApiOptions>? options = null,
Action<ServiceDiscoveryFacade>? discovery = null, Action<ResourceGraphBuilder>? resources = null, IMvcCoreBuilder? mvcBuilder = null,
ICollection<Type>? dbContextTypes = null)
#pragma warning restore AV1553 // Do not use optional parameters with default value null for strings, collections or tasks
{
ArgumentGuard.NotNull(services, nameof(services));

Expand Down
8 changes: 7 additions & 1 deletion src/JsonApiDotNetCore/Diagnostics/CascadingCodeTimer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ static CascadingCodeTimer()
}

/// <inheritdoc />
public IDisposable Measure(string name, bool excludeInRelativeCost = false)
public IDisposable Measure(string name)
{
return Measure(name, false);
}

/// <inheritdoc />
public IDisposable Measure(string name, bool excludeInRelativeCost)
{
MeasureScope childScope = CreateChildScope(name, excludeInRelativeCost);
_activeScopeStack.Push(childScope);
Expand Down
7 changes: 6 additions & 1 deletion src/JsonApiDotNetCore/Diagnostics/DisabledCodeTimer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ private DisabledCodeTimer()
{
}

public IDisposable Measure(string name, bool excludeInRelativeCost = false)
public IDisposable Measure(string name)
{
return this;
}

public IDisposable Measure(string name, bool excludeInRelativeCost)
{
return this;
}
Expand Down
13 changes: 11 additions & 2 deletions src/JsonApiDotNetCore/Diagnostics/ICodeTimer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ namespace JsonApiDotNetCore.Diagnostics;
/// </summary>
public interface ICodeTimer : IDisposable
{
/// <summary>
/// Starts recording the duration of a code block, while including this measurement in calculated percentages. Wrap this call in a <c>using</c>
/// statement, so the recording stops when the return value goes out of scope.
/// </summary>
/// <param name="name">
/// Description of what is being recorded.
/// </param>
IDisposable Measure(string name);

/// <summary>
/// Starts recording the duration of a code block. Wrap this call in a <c>using</c> statement, so the recording stops when the return value goes out of
/// scope.
Expand All @@ -13,9 +22,9 @@ public interface ICodeTimer : IDisposable
/// Description of what is being recorded.
/// </param>
/// <param name="excludeInRelativeCost">
/// When set, indicates to exclude this measurement in calculated percentages. <c>false</c> by default.
/// When set, indicates to exclude this measurement in calculated percentages.
/// </param>
IDisposable Measure(string name, bool excludeInRelativeCost = false);
IDisposable Measure(string name, bool excludeInRelativeCost);

/// <summary>
/// Returns intermediate or final results.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ public QueryableHandlerExpression(object queryableHandler, StringValues paramete
_parameterValue = parameterValue;
}

#pragma warning disable AV1130 // Return type in method signature should be an interface to an unchangeable collection
public IQueryable<TResource> Apply<TResource>(IQueryable<TResource> query)
where TResource : class, IIdentifiable
#pragma warning restore AV1130 // Return type in method signature should be an interface to an unchangeable collection
{
var handler = (Func<IQueryable<TResource>, StringValues, IQueryable<TResource>>)_queryableHandler;
return handler(query, _parameterValue);
Expand Down
6 changes: 3 additions & 3 deletions src/JsonApiDotNetCore/Queries/FieldSelection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ public sealed class FieldSelection : Dictionary<ResourceType, FieldSelectors>
{
public bool IsEmpty => Values.All(selectors => selectors.IsEmpty);

public ISet<ResourceType> GetResourceTypes()
public IReadOnlySet<ResourceType> GetResourceTypes()
{
return Keys.ToHashSet();
}

#pragma warning disable AV1130 // Return type in method signature should be a collection interface instead of a concrete type
#pragma warning disable AV1130 // Return type in method signature should be an interface to an unchangeable collection
public FieldSelectors GetOrCreateSelectors(ResourceType resourceType)
#pragma warning restore AV1130 // Return type in method signature should be a collection interface instead of a concrete type
#pragma warning restore AV1130 // Return type in method signature should be an interface to an unchangeable collection
{
ArgumentGuard.NotNull(resourceType, nameof(resourceType));

Expand Down
7 changes: 6 additions & 1 deletion src/JsonApiDotNetCore/Queries/Internal/Parsing/Token.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ public sealed class Token
public TokenKind Kind { get; }
public string? Value { get; }

public Token(TokenKind kind, string? value = null)
public Token(TokenKind kind)
{
Kind = kind;
}

public Token(TokenKind kind, string value)
: this(kind)
{
Value = value;
}

Expand Down
8 changes: 3 additions & 5 deletions src/JsonApiDotNetCore/Queries/Internal/QueryLayerComposer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,7 @@ public QueryLayer ComposeSecondaryLayerForRelationship(ResourceType secondaryRes
return secondaryLayer;
}

#pragma warning disable AV1130 // Return type in method signature should be a collection interface instead of a concrete type
private FieldSelection GetSelectionForRelationship(ResourceType secondaryResourceType)
#pragma warning restore AV1130 // Return type in method signature should be a collection interface instead of a concrete type
{
var selection = new FieldSelection();
FieldSelectors selectors = selection.GetOrCreateSelectors(secondaryResourceType);
Expand Down Expand Up @@ -404,7 +402,7 @@ public QueryLayer ComposeForUpdate<TId>(TId id, ResourceType primaryResourceType
foreach (RelationshipAttribute relationship in _targetedFields.Relationships)
{
object? rightValue = relationship.GetValue(primaryResource);
ICollection<IIdentifiable> rightResourceIds = _collectionConverter.ExtractResources(rightValue);
HashSet<IIdentifiable> rightResourceIds = _collectionConverter.ExtractResources(rightValue).ToHashSet(IdentifiableComparer.Instance);

if (rightResourceIds.Any())
{
Expand Down Expand Up @@ -527,9 +525,9 @@ protected virtual PaginationExpression GetPagination(IReadOnlyCollection<QueryEx
return pagination;
}

#pragma warning disable AV1130 // Return type in method signature should be a collection interface instead of a concrete type
#pragma warning disable AV1130 // Return type in method signature should be an interface to an unchangeable collection
protected virtual FieldSelection? GetSelectionForSparseAttributeSet(ResourceType resourceType)
#pragma warning restore AV1130 // Return type in method signature should be a collection interface instead of a concrete type
#pragma warning restore AV1130 // Return type in method signature should be an interface to an unchangeable collection
{
ArgumentGuard.NotNull(resourceType, nameof(resourceType));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private Expression CreateLambdaBodyInitializer(FieldSelection selection, Resourc
private Expression CreateLambdaBodyInitializerForTypeHierarchy(FieldSelection selection, ResourceType baseResourceType,
IEnumerable<IEntityType> concreteEntityTypes, LambdaScope lambdaScope)
{
ISet<ResourceType> resourceTypes = selection.GetResourceTypes();
IReadOnlySet<ResourceType> resourceTypes = selection.GetResourceTypes();
Expression rootCondition = lambdaScope.Accessor;

foreach (IEntityType entityType in concreteEntityTypes)
Expand Down
Loading