Skip to content
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
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"rollForward": false
},
"purview.build": {
"version": "0.5.4",
"version": "0.7.1",
"commands": [
"purview-build"
],
Expand Down
8 changes: 5 additions & 3 deletions .config/purview-build.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"Solution": "src/AspireC4.slnx",
"TestRoot": "src/tests",
"TestPatterns": "*Tests.csproj",
"TestFilter": "/*/*/*/*[Category=Unit]"
"TestFilter": "/*/*/*/*"
},
"PackValidation": {
// AspireC4.EntityFrameworkCore is analyzer-only (IncludeBuildOutput=false), so NuGet produces
Expand All @@ -25,7 +25,9 @@
// versions forced this check on and could not be configured off, so these packages have
// always been validated against it; declaring it keeps that behaviour. The analyzer-only
// package is unaffected either way: it ships no PDB, so it is never inspected.
"RequiredCompilerFlags": ["optimization=release"],
"RequiredCompilerFlags": [
"optimization=release"
],
// RequireExplicitContent defaults to true, so this is the exhaustive declaration of what each
// package ships: a package with no rule here, or an entry matching none of its globs, fails
// validation. The lib/ paths are literal net10.0 and must be updated alongside the target
Expand Down Expand Up @@ -74,4 +76,4 @@
"Release": {
"Mode": "None"
}
}
}
158 changes: 88 additions & 70 deletions .editorconfig

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ on:
push:
branches: [main]

permissions:
contents: write
# The shared release workflow pushes the same packages to nuget.org and, when
# PURVIEW_PUBLISH_GITHUB_PACKAGES=true, to GitHub Packages. A reusable workflow cannot grant
# more than its caller, so the permission is declared here.
packages: write

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
Expand Down
14 changes: 5 additions & 9 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@
<PropertyGroup>
<RoslynCompilerVersion>5.9.0</RoslynCompilerVersion>
<RoslynAnalyzersVersion>5.9.0</RoslynAnalyzersVersion>
<TUnitVersion>1.75.0</TUnitVersion>
<PurviewSourceGenVersion>1.1.1</PurviewSourceGenVersion>
<PurviewTelemetryVersion>5.0.4</PurviewTelemetryVersion>
<AspireVersion>13.6.1</AspireVersion>
<TUnitVersion>1.76.0</TUnitVersion>
<PurviewSourceGenVersion>1.2.0</PurviewSourceGenVersion>
<PurviewTelemetryVersion>5.0.5</PurviewTelemetryVersion>
<AspireVersion>13.6.3</AspireVersion>
</PropertyGroup>

<ItemGroup Label="Transitive Pinning">
<PackageVersion Include="MessagePack" Version="2.5.307" />
</ItemGroup>

<ItemGroup>
<PackageVersion Include="Aspire.Hosting" Version="$(AspireVersion)" />
<PackageVersion Include="Aspire.Hosting.Testing" Version="$(AspireVersion)" />
Expand Down Expand Up @@ -49,6 +45,6 @@
<PackageVersion Include="TUnit.Aspire" Version="$(TUnitVersion)" />
<PackageVersion Include="TUnit.Core" Version="$(TUnitVersion)" />
<PackageVersion Include="TUnit.Mocks" Version="$(TUnitVersion)" />
<PackageVersion Include="Purview.Skills.Testing" Version="1.0.7" />
<PackageVersion Include="Purview.Skills.Testing" Version="1.1.0" />
</ItemGroup>
</Project>
8 changes: 5 additions & 3 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{
"sdk": {
"allowPrerelease": false
"version": "11.0.100-rc.2.26504.105",
"rollForward": "latestMajor",
"allowPrerelease": true
},
"msbuild-sdks": {
"Purview.BuildSdk": "1.0.7"
"Purview.BuildSdk": "1.1.0"
},
"test": {
"runner": "Microsoft.Testing.Platform"
}
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aspirec4",
"version": "13.6.0-preview.1",
"version": "13.6.0-preview.2",
"license": "MIT",
"description": "Aspire LikeC4 Visualization - version manifest for CD pipeline",
"author": {
Expand Down Expand Up @@ -32,4 +32,4 @@
"engines": {
"node": ">=22.19.18"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ HashSet<string> uniqueFromIndexes
|| HasAttribute(property, EfTypes.Attributes.Required)
|| !StoreTypeMap.IsNullable(property.Type);

var domainType = DomainType(property.Type, complexType: null);
var (name, kind) = DomainType(property.Type, complexType: null);

return new ColumnShape
{
Expand All @@ -237,8 +237,8 @@ HashSet<string> uniqueFromIndexes
?? GetAttributeNamedString(property, EfTypes.Attributes.Column, "TypeName")
?? StoreTypeMap.ColumnStoreType(property.Type),
ClrTypeName = property.Type.ToDisplayString(),
DomainTypeName = domainType.Name,
DomainTypeKind = domainType.Kind,
DomainTypeName = name,
DomainTypeKind = kind,
IsNullable = !isRequired,
IsUnique =
uniqueFromIndexes.Contains(property.Name) || config?.UniqueProperties.Contains(property.Name) == true,
Expand Down Expand Up @@ -294,7 +294,7 @@ static void AddComplexColumns(TableShape table, string prefix, ITypeSymbol compl
continue;
}

var domainType = DomainType(member.Type, named.Name);
var (name, kind) = DomainType(member.Type, named.Name);

table.Columns.Add(
new ColumnShape
Expand All @@ -303,8 +303,8 @@ static void AddComplexColumns(TableShape table, string prefix, ITypeSymbol compl
Name = GetAttributeString(member, EfTypes.Attributes.Column, 0) ?? $"{prefix}_{member.Name}",
StoreType = StoreTypeMap.ColumnStoreType(member.Type),
ClrTypeName = member.Type.ToDisplayString(),
DomainTypeName = domainType.Name,
DomainTypeKind = domainType.Kind,
DomainTypeName = name,
DomainTypeKind = kind,
IsNullable = nullable || StoreTypeMap.IsNullable(member.Type),
MaxLength =
GetAttributeInt(member, EfTypes.Attributes.MaxLength, 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,9 @@ static bool IsNamedEnumMember(TypedConstant constant, string member)
}

if (string.Equals(constant.Value.ToString(), member, StringComparison.Ordinal))
{
return true;
}

// The constant is not the member name, so check whether it is the underlying value of the member.
return constant.Type is INamedTypeSymbol { TypeKind: TypeKind.Enum } enumType
&& enumType
.GetMembers()
Expand Down
12 changes: 6 additions & 6 deletions src/src/EntityFrameworkCore.ModelDump/EfModelDumpProjector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Aspire.Hosting.AspireC4.EntityFrameworkCore.ModelDump;
/// the real model — conventions, value converters and composite foreign keys included. The output is
/// deliberately the diagram's own contract rather than the raw model, so the artifact stays small.
/// </remarks>
public static class EfModelDumpProjector
static class EfModelDumpProjector
{
const string UnknownStoreType = "unknown";

Expand Down Expand Up @@ -85,16 +85,16 @@ static DumpTable Table(IEntityType entityType)

foreach (var (property, complexType) in Columns(entityType))
{
var domainType = DomainType(property, complexType);
var (name, kind) = DomainType(property, complexType);

columns.Add(
new DumpColumn
{
Name = property.GetColumnName(),
StoreType = ResolveStoreType(ProviderType(property)),
ClrTypeName = property.ClrType.FullName,
DomainTypeName = domainType.Name,
DomainTypeKind = domainType.Kind,
DomainTypeName = name,
DomainTypeKind = kind,
IsNullable = property.IsNullable,
IsPrimaryKey = property.IsPrimaryKey(),
IsUnique = uniqueProperties.Contains(property),
Expand Down Expand Up @@ -249,10 +249,10 @@ static string ResolveStoreType(Type type)
}

if (unwrapped == typeof(byte[]))
{
return "blob";
}

// The AppHost's rule for value objects is to use the provider type, which is what EF stores in the
// database. The provider type is already unwrapped, so the nullable check above is only for enums.
return unwrapped.FullName switch
{
"System.Boolean" => "bool",
Expand Down
2 changes: 1 addition & 1 deletion src/src/EntityFrameworkCore.ModelDump/EfModelDumpRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Aspire.Hosting.AspireC4.EntityFrameworkCore.ModelDump;
/// composite foreign keys included. The output directory is the project's <c>obj/</c>, so nothing it
/// writes is deployed or committed.
/// </remarks>
public static class EfModelDumpRunner
static class EfModelDumpRunner
{
/// <summary>Dumps every context the assembly's design-time factories expose.</summary>
/// <param name="assemblyPath">The built assembly to read contexts from.</param>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Aspire.Hosting.AspireC4.EntityFrameworkCore.UnitTests")]
1 change: 0 additions & 1 deletion src/src/EntityFrameworkCore/Dbml/DbmlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ static void WriteColumn(StringBuilder sb, EfColumn column, AspireC4EfDiagramOpti
static void WriteReferences(StringBuilder sb, EfModel model, AspireC4EfDiagramOptions options)
{
Dictionary<string, (EfContext Context, EfTable Table)> byName = new(StringComparer.OrdinalIgnoreCase);

foreach (var context in model.Contexts)
{
foreach (var table in context.Tables)
Expand Down
6 changes: 4 additions & 2 deletions src/src/EntityFrameworkCore/EfColumnTypeDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public static string Primary(EfColumn column, AspireC4EfDiagramOptions options)
ArgumentNullException.ThrowIfNull(options);

if (string.IsNullOrEmpty(column.DomainTypeName))
{
return DatabaseType(column);
}

// The domain type is present, so the headline is either the domain type or the database type,
// depending on the configured display order.
return options.DomainTypeDisplay is DomainTypeDisplay.DatabaseFirst or DomainTypeDisplay.DatabaseOnly
? DatabaseType(column)
: column.DomainTypeName;
Expand All @@ -56,6 +56,7 @@ public static string Primary(EfColumn column, AspireC4EfDiagramOptions options)

var marker = column.DomainTypeKind == EfDomainTypeKind.Enum;

#pragma warning disable IDE0072 // Add missing cases
return options.DomainTypeDisplay switch
{
DomainTypeDisplay.DomainTypeFirst => marker ? $"{DatabaseType(column)}, enum" : DatabaseType(column),
Expand All @@ -64,6 +65,7 @@ public static string Primary(EfColumn column, AspireC4EfDiagramOptions options)
DomainTypeDisplay.DomainTypeOnly => DatabaseType(column),
_ => null,
};
#pragma warning restore IDE0072 // Add missing cases
}

/// <summary>Composes the inline label, e.g. <c>AssetId (guid)</c> or <c>ActorType (int, enum)</c>.</summary>
Expand Down
12 changes: 6 additions & 6 deletions src/src/EntityFrameworkCore/EfModelMetadataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ static TableShape BuildTable(Type entity, string defaultName, Dictionary<Type, s

static ColumnShape BuildColumn(PropertyInfo property, HashSet<string> uniqueFromIndexes)
{
var domainType = DomainType(property.PropertyType, complexType: null);
var (name, kind) = DomainType(property.PropertyType, complexType: null);

return new ColumnShape
{
Expand All @@ -389,8 +389,8 @@ static ColumnShape BuildColumn(PropertyInfo property, HashSet<string> uniqueFrom
StoreType =
GetAttributeNamedString(property, "Column", "TypeName") ?? ColumnStoreType(property.PropertyType),
ClrTypeName = property.PropertyType.FullName,
DomainTypeName = domainType.Name,
DomainTypeKind = domainType.Kind,
DomainTypeName = name,
DomainTypeKind = kind,
IsNullable = IsNullable(property),
IsUnique = uniqueFromIndexes.Contains(property.Name),
MaxLength = GetAttributeInt(property, "MaxLength", 0) ?? GetAttributeInt(property, "StringLength", 0),
Expand Down Expand Up @@ -437,7 +437,7 @@ static void AddComplexColumns(TableShape table, string prefix, Type complexType,
continue;
}

var domainType = DomainType(member.PropertyType, Unwrap(complexType).Name);
var (name, kind) = DomainType(member.PropertyType, Unwrap(complexType).Name);

table.Columns.Add(
new ColumnShape
Expand All @@ -446,8 +446,8 @@ static void AddComplexColumns(TableShape table, string prefix, Type complexType,
Name = GetAttributeString(member, "Column", 0) ?? $"{prefix}_{member.Name}",
StoreType = ColumnStoreType(member.PropertyType),
ClrTypeName = member.PropertyType.FullName,
DomainTypeName = domainType.Name,
DomainTypeKind = domainType.Kind,
DomainTypeName = name,
DomainTypeKind = kind,
IsNullable = nullable || IsNullable(member),
MaxLength = GetAttributeInt(member, "MaxLength", 0) ?? GetAttributeInt(member, "StringLength", 0),
Comment = GetAttributeString(member, "Comment", 0),
Expand Down
3 changes: 1 addition & 2 deletions src/src/EntityFrameworkCore/EfRelationshipName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ public static string Label(EfForeignKey foreignKey)
}

if (!string.IsNullOrEmpty(principal))
{
return $"? → {principal}";
}

// If neither end is named, fall back to the constraint name, and then to the columns.
return !string.IsNullOrEmpty(foreignKey.ConstraintName)
? foreignKey.ConstraintName
: string.Join(", ", foreignKey.Columns);
Expand Down
4 changes: 2 additions & 2 deletions src/src/SourceGenerators/LikeC4StrictValidatorGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public void Initialize(IncrementalGeneratorInitializationContext context)

context.RegisterPostInitializationOutput(ctx =>
{
foreach (var (HintName, Source) in MarkerAttributeEmitter.EmitMarkAttribute())
ctx.AddSource(HintName, Source);
foreach (var (hintName, source) in MarkerAttributeEmitter.EmitMarkAttribute())
ctx.AddSource(hintName, source);
});

// Combine everything and validate.
Expand Down
2 changes: 1 addition & 1 deletion src/src/TestAppHost/TestAppHost.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Aspire.AppHost.Sdk/13.6.1">
<Project Sdk="Aspire.AppHost.Sdk/13.6.3">
<PropertyGroup>
<OutputType>Exe</OutputType>
<AspireUseCliBundle>true</AspireUseCliBundle>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ async Task<string> GenerateDescriptorAsync(string source, CancellationToken canc
public async Task RunGenerator_Always_EmitsTheModelAttributeType(CancellationToken cancellationToken)
{
// Arrange
const string Source = "namespace Sample;";
const string source = "namespace Sample;";

// Act
using var result = await GenerateAsync(Source, cancellationToken: cancellationToken);
using var result = await GenerateAsync(source, cancellationToken: cancellationToken);

// Assert
await Assert.That(result.Generated()).HasGeneratedSyntaxTree("AspireC4EfModelAttribute.g.cs");
Expand All @@ -61,10 +61,10 @@ public async Task RunGenerator_Always_EmitsTheModelAttributeType(CancellationTok
public async Task RunGenerator_WithNoDbContext_EmitsNoDescriptor(CancellationToken cancellationToken)
{
// Arrange
const string Source = "namespace Sample; public class NotAContext { }";
const string source = "namespace Sample; public class NotAContext { }";

// Act
var descriptor = await GenerateDescriptorAsync(Source, cancellationToken);
var descriptor = await GenerateDescriptorAsync(source, cancellationToken);

// Assert
await Assert.That(descriptor).IsEmpty();
Expand Down Expand Up @@ -404,7 +404,7 @@ CancellationToken cancellationToken
)
{
// Arrange
const string Source = """
const string source = """
using Microsoft.EntityFrameworkCore;

namespace Sample;
Expand All @@ -413,7 +413,7 @@ public class EmptyDbContext : DbContext { }
""";

// Act
using var result = await GenerateAsync(Source, cancellationToken: cancellationToken);
using var result = await GenerateAsync(source, cancellationToken: cancellationToken);

// Assert
await Assert.That(result).HasDiagnostic(DiagnosticLibrary.NoEntityTypesDiscovered);
Expand Down
Loading
Loading