Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 0 additions & 2 deletions src/Models/IImages.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Ipfs;

namespace WindowsAppCommunity.Sdk.Models;

/// <summary>
Expand Down
18 changes: 17 additions & 1 deletion src/Models/IProjectRoleCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,21 @@ public interface IProjectRoleCollection
/// <summary>
/// Represents a list of registered projects along with the role on each.
/// </summary>
(Cid ProjectId, DagCid RoleCid)[] Projects { get; set; }
ProjectRole[] Projects { get; set; }
}

/// <summary>
/// A container for a project and a corresponding role.
/// </summary>
public record ProjectRole
{
/// <summary>
/// The project ID.
/// </summary>
public required Cid ProjectId { get; init; }

/// <summary>
/// The role of the project.
/// </summary>
public required DagCid Role { get; init; }
}
18 changes: 17 additions & 1 deletion src/Models/IPublisherRoleCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,21 @@ public interface IPublisherRoleCollection
/// <summary>
/// Represents a list of registered publishers along with the role on each.
/// </summary>
public (Cid PublisherId, DagCid RoleCid)[] Publishers { get; set; }
public PublisherRole[] Publishers { get; set; }
}

/// <summary>
/// A container for a Publisher and a corresponding role.
/// </summary>
public record PublisherRole
{
/// <summary>
/// The publisher ID.
/// </summary>
public required Cid PublisherId { get; init; }

/// <summary>
/// The role of the publisher.
/// </summary>
public required DagCid Role { get; init; }
}
18 changes: 17 additions & 1 deletion src/Models/IUserRoleCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,21 @@ public interface IUserRoleCollection
/// <summary>
/// Represents a list of registered users along with the role on each.
/// </summary>
public (Cid UserId, DagCid RoleCid)[] Users { get; set; }
public UserRole[] Users { get; set; }
}

/// <summary>
/// A container for a user and a corresponding role.
/// </summary>
public record UserRole
{
/// <summary>
/// The user ID.
/// </summary>
public required Cid UserId { get; init; }

/// <summary>
/// The role of the user.
/// </summary>
public required DagCid Role { get; init; }
}
10 changes: 5 additions & 5 deletions src/Models/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ public record Project : IEntity, IUserRoleCollection, IAccentColor, IProjectColl
/// <summary>
/// The name of this project.
/// </summary>
public required string Name { get; set; }
public string Name { get; set; } = string.Empty;

/// <summary>
/// A description of this project.
/// </summary>
public required string Description { get; set; }
public string Description { get; set; } = string.Empty;

/// <summary>
/// An extended description of this project.
/// </summary>
public required string ExtendedDescription { get; set; }
public string ExtendedDescription { get; set; } = string.Empty;

/// <summary>
/// A list of <see cref="Image"/>s demonstrating this project.
Expand All @@ -47,7 +47,7 @@ public record Project : IEntity, IUserRoleCollection, IAccentColor, IProjectColl
/// <summary>
/// The category defining this project, as found in an app store.
/// </summary>
public required string Category { get; set; }
public string Category { get; set; } = string.Empty;

/// <summary>
/// Other projects which this project may depend on for various reasons.
Expand All @@ -57,7 +57,7 @@ public record Project : IEntity, IUserRoleCollection, IAccentColor, IProjectColl
/// <summary>
/// The <see cref="User"/>s who collaborate on this project, and their corresponding roles.
/// </summary>
public (Cid, DagCid)[] Users { get; set; } = [];
public UserRole[] Users { get; set; } = [];

/// <summary>
/// Represents links to external profiles or resources added by the user.
Expand Down
8 changes: 4 additions & 4 deletions src/Models/Publisher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ public record Publisher : IEntity, ILinkCollection, IProjectCollection, IUserRol
/// <summary>
/// The name of the publisher.
/// </summary>
public required string Name { get; set; }
public string Name { get; set; } = string.Empty;

/// <summary>
/// A description of the publisher.
/// </summary>
public required string Description { get; set; }
public string Description { get; set; } = string.Empty;

/// <summary>
/// An extended description of the publisher.
/// </summary>
public required string ExtendedDescription { get; set; }
public string ExtendedDescription { get; set; } = string.Empty;

/// <summary>
/// A hex-encoded accent color for this publisher.
Expand All @@ -42,7 +42,7 @@ public record Publisher : IEntity, ILinkCollection, IProjectCollection, IUserRol
/// <summary>
/// Users who are registered to participate in this publisher, along with their roles.
/// </summary>
public (Cid, DagCid)[] Users { get; set; } = [];
public UserRole[] Users { get; set; } = [];

/// <summary>
/// Projects who are registered under this publisher.
Expand Down
10 changes: 5 additions & 5 deletions src/Models/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ public record User : IEntity, IConnections, ILinkCollection, IProjectRoleCollect
/// <summary>
/// The name of the user.
/// </summary>
public required string Name { get; set; }
public string Name { get; set; } = string.Empty;

/// <summary>
/// A description of the user. Supports markdown.
/// </summary>
public required string Description { get; set; }
public string Description { get; set; } = string.Empty;

/// <summary>
/// An extended description of the user. Supports markdown.
/// </summary>
public required string ExtendedDescription { get; set; }
public string ExtendedDescription { get; set; } = string.Empty;

/// <summary>
/// Represents application connections added by the user.
Expand All @@ -42,12 +42,12 @@ public record User : IEntity, IConnections, ILinkCollection, IProjectRoleCollect
/// <summary>
/// A list of all the projects the user is registered with, along with their role on the project.
/// </summary>
public (Cid, DagCid)[] Projects { get; set; } = [];
public ProjectRole[] Projects { get; set; } = [];

/// <summary>
/// Represents all publishers the user is registered with, along with their roles.
/// </summary>
public (Cid, DagCid)[] Publishers { get; set; } = [];
public PublisherRole[] Publishers { get; set; } = [];

/// <summary>
/// A flag that indicates whether the profile has requested to be forgotten.
Expand Down
1 change: 0 additions & 1 deletion src/Nomad/ModifiableEntity.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Diagnostics;
using CommunityToolkit.Diagnostics;
using Ipfs;
using OwlCore.ComponentModel;
Expand Down
4 changes: 2 additions & 2 deletions src/Nomad/ModifiableProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class ModifiableProject : NomadKuboEventStreamHandler<ValueUpdateEvent>,
/// <param name="client">The client used to interact with the ipfs network.</param>
/// <param name="kuboOptions">The options used to read and write data to and from Kubo.</param>
/// <returns>A new instance of <see cref="ModifiableProject"/>.</returns>
public static ModifiableProject FromHandlerConfig(NomadKuboEventStreamHandlerConfig<Project> handlerConfig, NomadKuboRepository<ModifiableProject, IReadOnlyProject, Project, ValueUpdateEvent> projectDependencyRepository, NomadKuboRepository<ModifiablePublisher, IReadOnlyPublisher, Publisher, ValueUpdateEvent> publisherRepository, NomadKuboRepository<ModifiableUser, IReadOnlyUser, User, ValueUpdateEvent> userRepository, ICoreApi client, IKuboOptions kuboOptions)
public static ModifiableProject FromHandlerConfig(NomadKuboEventStreamHandlerConfig<Project> handlerConfig, INomadKuboRepositoryBase<ModifiableProject, IReadOnlyProject> projectDependencyRepository, INomadKuboRepositoryBase<ModifiablePublisher, IReadOnlyPublisher> publisherRepository, INomadKuboRepositoryBase<ModifiableUser, IReadOnlyUser> userRepository, ICoreApi client, IKuboOptions kuboOptions)
{
Guard.IsNotNull(handlerConfig.RoamingValue);
Guard.IsNotNull(handlerConfig.RoamingKey);
Expand Down Expand Up @@ -168,7 +168,7 @@ public static ModifiableProject FromHandlerConfig(NomadKuboEventStreamHandlerCon
/// <summary>
/// A repository to get modifiable or readonly project instances from.
/// </summary>
public required NomadKuboRepository<ModifiablePublisher, IReadOnlyPublisher, Publisher, ValueUpdateEvent> PublisherRepository { get; init; }
public required INomadKuboRepositoryBase<ModifiablePublisher, IReadOnlyPublisher> PublisherRepository { get; init; }

/// <inheritdoc/>
public string Category => InnerProject.Category;
Expand Down
3 changes: 1 addition & 2 deletions src/Nomad/ModifiableProjectCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using OwlCore.Nomad;
using OwlCore.Nomad.Kubo;
using OwlCore.Nomad.Kubo.Events;
using WindowsAppCommunity.Sdk.Models;

namespace WindowsAppCommunity.Sdk.Nomad;

Expand All @@ -23,7 +22,7 @@ public class ModifiableProjectCollection : NomadKuboEventStreamHandler<ValueUpda
/// <summary>
/// The repository to use for getting modifiable or readonly project instances.
/// </summary>
public required NomadKuboRepository<ModifiableProject, IReadOnlyProject, Project, ValueUpdateEvent> ProjectRepository { get; init; }
public required INomadKuboRepositoryBase<ModifiableProject, IReadOnlyProject> ProjectRepository { get; init; }

/// <inheritdoc/>
public event EventHandler<IReadOnlyProject[]>? ProjectsAdded;
Expand Down
6 changes: 3 additions & 3 deletions src/Nomad/ModifiableProjectRoleCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class ModifiableProjectRoleCollection : NomadKuboEventStreamHandler<Value
/// <summary>
/// The repository to use for getting modifiable or readonly project instances.
/// </summary>
public required NomadKuboRepository<ModifiableProject, IReadOnlyProject, Project, ValueUpdateEvent> ProjectRepository { get; init; }
public required INomadKuboRepositoryBase<ModifiableProject, IReadOnlyProject> ProjectRepository { get; init; }

/// <inheritdoc/>
public event EventHandler<IReadOnlyProjectRole[]>? ProjectsAdded;
Expand Down Expand Up @@ -108,15 +108,15 @@ public override async Task ApplyEntryUpdateAsync(EventStreamEntry<DagCid> stream
public async Task ApplyAddProjectRoleEntryAsync(EventStreamEntry<DagCid> streamEntry, ValueUpdateEvent updateEvent, IReadOnlyProjectRole project, CancellationToken cancellationToken)
{
var roleCid = await Client.Dag.PutAsync(project.Role, pin: KuboOptions.ShouldPin, cancel: cancellationToken);
Inner.Inner.Projects = [.. Inner.Inner.Projects, (project.Id, (DagCid)roleCid)];
Inner.Inner.Projects = [.. Inner.Inner.Projects, new ProjectRole { ProjectId = project.Id, Role = (DagCid)roleCid }];
ProjectsAdded?.Invoke(this, [project]);
}

/// <inheritdoc/>
public async Task ApplyRemoveProjectRoleEntryAsync(EventStreamEntry<DagCid> streamEntry, ValueUpdateEvent updateEvent, IReadOnlyProjectRole project, CancellationToken cancellationToken)
{
var roleCid = await Client.Dag.PutAsync(project.Role, pin: KuboOptions.ShouldPin, cancel: cancellationToken);
Inner.Inner.Projects = [.. Inner.Inner.Projects.Where(x => x.ProjectId != project.Id && x.RoleCid != (DagCid)roleCid)];
Inner.Inner.Projects = [.. Inner.Inner.Projects.Where(x => x.ProjectId != project.Id && x.Role != (DagCid)roleCid)];
ProjectsRemoved?.Invoke(this, [project]);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Nomad/ModifiablePublisher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class ModifiablePublisher : NomadKuboEventStreamHandler<ValueUpdateEvent>
/// <param name="client">The client used to interact with the ipfs network.</param>
/// <param name="kuboOptions">The options used to read and write data to and from Kubo.</param>
/// <returns>A new instance of <see cref="ModifiablePublisher"/>.</returns>
public static ModifiablePublisher FromHandlerConfig(NomadKuboEventStreamHandlerConfig<Publisher> handlerConfig, NomadKuboRepository<ModifiableProject, IReadOnlyProject, Project, ValueUpdateEvent> projectDependencyRepository, NomadKuboRepository<ModifiablePublisher, IReadOnlyPublisher, Publisher, ValueUpdateEvent> publisherRepository, NomadKuboRepository<ModifiableUser, IReadOnlyUser, User, ValueUpdateEvent> userRepository, ICoreApi client, IKuboOptions kuboOptions)
public static ModifiablePublisher FromHandlerConfig(NomadKuboEventStreamHandlerConfig<Publisher> handlerConfig, INomadKuboRepositoryBase<ModifiableProject, IReadOnlyProject> projectDependencyRepository, INomadKuboRepositoryBase<ModifiablePublisher, IReadOnlyPublisher> publisherRepository, INomadKuboRepositoryBase<ModifiableUser, IReadOnlyUser> userRepository, ICoreApi client, IKuboOptions kuboOptions)
{
Guard.IsNotNull(handlerConfig.RoamingValue);
Guard.IsNotNull(handlerConfig.RoamingKey);
Expand Down
3 changes: 1 addition & 2 deletions src/Nomad/ModifiablePublisherCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using OwlCore.Nomad;
using OwlCore.Nomad.Kubo;
using OwlCore.Nomad.Kubo.Events;
using WindowsAppCommunity.Sdk.Models;

namespace WindowsAppCommunity.Sdk.Nomad;

Expand All @@ -25,7 +24,7 @@ public class ModifiablePublisherCollection : NomadKuboEventStreamHandler<ValueUp
/// <summary>
/// The repository to use for getting modifiable or readonly publisher instances.
/// </summary>
public required NomadKuboRepository<ModifiablePublisher, IReadOnlyPublisher, Publisher, ValueUpdateEvent> PublisherRepository { get; init; }
public required INomadKuboRepositoryBase<ModifiablePublisher, IReadOnlyPublisher> PublisherRepository { get; init; }

/// <inheritdoc/>
public event EventHandler<IReadOnlyPublisher[]>? PublishersAdded;
Expand Down
6 changes: 3 additions & 3 deletions src/Nomad/ModifiablePublisherRoleCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class ModifiablePublisherRoleCollection : NomadKuboEventStreamHandler<Val
/// <summary>
/// The repository to use for getting modifiable or readonly publisher instances.
/// </summary>
public required NomadKuboRepository<ModifiablePublisher, IReadOnlyPublisher, Publisher, ValueUpdateEvent> PublisherRepository { get; init; }
public required INomadKuboRepositoryBase<ModifiablePublisher, IReadOnlyPublisher> PublisherRepository { get; init; }

/// <inheritdoc/>
public event EventHandler<IReadOnlyPublisherRole[]>? PublishersAdded;
Expand Down Expand Up @@ -140,15 +140,15 @@ public override async Task ApplyEntryUpdateAsync(EventStreamEntry<DagCid> stream
public async Task ApplyAddPublisherRoleEntryAsync(EventStreamEntry<DagCid> streamEntry, ValueUpdateEvent updateEvent, IReadOnlyPublisherRole publisher, CancellationToken cancellationToken)
{
var roleCid = await Client.Dag.PutAsync(publisher.Role, pin: KuboOptions.ShouldPin, cancel: cancellationToken);
Inner.Inner.Publishers = [.. Inner.Inner.Publishers, (publisher.Id, (DagCid)roleCid)];
Inner.Inner.Publishers = [.. Inner.Inner.Publishers, new PublisherRole { PublisherId = publisher.Id, Role = (DagCid)roleCid }];
PublishersAdded?.Invoke(this, [publisher]);
}

/// <inheritdoc/>
public async Task ApplyRemovePublisherRoleEntryAsync(EventStreamEntry<DagCid> streamEntry, ValueUpdateEvent updateEvent, IReadOnlyPublisherRole publisher, CancellationToken cancellationToken)
{
var roleCid = await Client.Dag.PutAsync(publisher.Role, pin: KuboOptions.ShouldPin, cancel: cancellationToken);
Inner.Inner.Publishers = [.. Inner.Inner.Publishers.Where(x => x.PublisherId != publisher.Id && x.RoleCid != (DagCid)roleCid)];
Inner.Inner.Publishers = [.. Inner.Inner.Publishers.Where(x => x.PublisherId != publisher.Id && x.Role != (DagCid)roleCid)];
PublishersRemoved?.Invoke(this, [publisher]);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Nomad/ModifiableUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class ModifiableUser : NomadKuboEventStreamHandler<ValueUpdateEvent>, IMo
/// <param name="client">The client used to interact with the ipfs network.</param>
/// <param name="kuboOptions">The options used to read and write data to and from Kubo.</param>
/// <returns>A new instance of <see cref="ModifiableUser"/>.</returns>
public static ModifiableUser FromHandlerConfig(NomadKuboEventStreamHandlerConfig<User> handlerConfig, NomadKuboRepository<ModifiableProject, IReadOnlyProject, Project, ValueUpdateEvent> projectDependencyRepository, NomadKuboRepository<ModifiablePublisher, IReadOnlyPublisher, Publisher, ValueUpdateEvent> publisherRepository, ICoreApi client, IKuboOptions kuboOptions)
public static ModifiableUser FromHandlerConfig(NomadKuboEventStreamHandlerConfig<User> handlerConfig, INomadKuboRepositoryBase<ModifiableProject, IReadOnlyProject> projectDependencyRepository, INomadKuboRepositoryBase<ModifiablePublisher, IReadOnlyPublisher> publisherRepository, ICoreApi client, IKuboOptions kuboOptions)
{
Guard.IsNotNull(handlerConfig.RoamingValue);
Guard.IsNotNull(handlerConfig.RoamingKey);
Expand Down
8 changes: 4 additions & 4 deletions src/Nomad/ModifiableUserRoleCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
using OwlCore.Nomad;
using OwlCore.Nomad.Kubo;
using OwlCore.Nomad.Kubo.Events;
using User = WindowsAppCommunity.Sdk.Models.User;
using CommunityToolkit.Diagnostics;
using WindowsAppCommunity.Sdk.Models;

namespace WindowsAppCommunity.Sdk.Nomad;

Expand All @@ -23,7 +23,7 @@ public class ModifiableUserRoleCollection : NomadKuboEventStreamHandler<ValueUpd
/// <summary>
/// The repository to use for getting modifiable or readonly user instances.
/// </summary>
public required NomadKuboRepository<ModifiableUser, IReadOnlyUser, User, ValueUpdateEvent> UserRepository { get; init; }
public required INomadKuboRepositoryBase<ModifiableUser, IReadOnlyUser> UserRepository { get; init; }

/// <inheritdoc/>
public event EventHandler<IReadOnlyUserRole[]>? UsersAdded;
Expand Down Expand Up @@ -147,15 +147,15 @@ public override async Task ApplyEntryUpdateAsync(EventStreamEntry<DagCid> stream
public async Task ApplyAddUserRoleEntryAsync(EventStreamEntry<DagCid> streamEntry, ValueUpdateEvent updateEvent, IReadOnlyUserRole user, CancellationToken cancellationToken)
{
var roleCid = await Client.Dag.PutAsync(user.Role, pin: KuboOptions.ShouldPin, cancel: cancellationToken);
Inner.Inner.Users = [.. Inner.Inner.Users, (user.Id, (DagCid)roleCid)];
Inner.Inner.Users = [.. Inner.Inner.Users, new UserRole { UserId = user.Id, Role = (DagCid)roleCid }];
UsersAdded?.Invoke(this, [user]);
}

/// <inheritdoc/>
public async Task ApplyRemoveUserRoleEntryAsync(EventStreamEntry<DagCid> streamEntry, ValueUpdateEvent updateEvent, IReadOnlyUserRole user, CancellationToken cancellationToken)
{
var roleCid = await Client.Dag.PutAsync(user.Role, pin: KuboOptions.ShouldPin, cancel: cancellationToken);
Inner.Inner.Users = [.. Inner.Inner.Users.Where(x => x.UserId != user.Id && x.RoleCid != (DagCid)roleCid)];
Inner.Inner.Users = [.. Inner.Inner.Users.Where(x => x.UserId != user.Id && x.Role != (DagCid)roleCid)];
UsersRemoved?.Invoke(this, [user]);
}

Expand Down
Loading