diff --git a/backend/LcmCrdt/Changes/CreateEntryChange.cs b/backend/LcmCrdt/Changes/CreateEntryChange.cs index b095419cf..5de870ac5 100644 --- a/backend/LcmCrdt/Changes/CreateEntryChange.cs +++ b/backend/LcmCrdt/Changes/CreateEntryChange.cs @@ -7,7 +7,7 @@ namespace LcmCrdt.Changes; -public class CreateEntryChange : Change, ISelfNamedType +public class CreateEntryChange : CreateChange, ISelfNamedType { public CreateEntryChange(MiniLcm.Entry entry) : base(entry.Id == Guid.Empty ? Guid.NewGuid() : entry.Id) { @@ -31,24 +31,15 @@ private CreateEntryChange(Guid entityId) : base(entityId) public MultiString? Note { get; set; } - public override IObjectBase NewEntity(Commit commit) + public override ValueTask NewEntity(Commit commit, ChangeContext context) { - return new Entry + return new(new Entry { Id = EntityId, LexemeForm = LexemeForm ?? new MultiString(), CitationForm = CitationForm ?? new MultiString(), LiteralMeaning = LiteralMeaning ?? new MultiString(), Note = Note ?? new MultiString() - }; - } - - public override ValueTask ApplyChange(Entry entity, ChangeContext context) - { - if (LexemeForm is not null) entity.LexemeForm = LexemeForm; - if (CitationForm is not null) entity.CitationForm = CitationForm; - if (LiteralMeaning is not null) entity.LiteralMeaning = LiteralMeaning; - if (Note is not null) entity.Note = Note; - return ValueTask.CompletedTask; + }); } } diff --git a/backend/LcmCrdt/Changes/CreateExampleSentenceChange.cs b/backend/LcmCrdt/Changes/CreateExampleSentenceChange.cs index f4840255b..ebcaa5786 100644 --- a/backend/LcmCrdt/Changes/CreateExampleSentenceChange.cs +++ b/backend/LcmCrdt/Changes/CreateExampleSentenceChange.cs @@ -7,7 +7,7 @@ namespace LcmCrdt.Changes; -public class CreateExampleSentenceChange: Change, ISelfNamedType +public class CreateExampleSentenceChange: CreateChange, ISelfNamedType { public CreateExampleSentenceChange(MiniLcm.ExampleSentence exampleSentence, Guid senseId) : base(exampleSentence.Id == Guid.Empty ? Guid.NewGuid() : exampleSentence.Id) @@ -30,7 +30,7 @@ private CreateExampleSentenceChange(Guid entityId, Guid senseId) : base(entityId public MultiString? Translation { get; set; } public string? Reference { get; set; } - public override IObjectBase NewEntity(Commit commit) + public override async ValueTask NewEntity(Commit commit, ChangeContext context) { return new ExampleSentence { @@ -38,18 +38,8 @@ public override IObjectBase NewEntity(Commit commit) SenseId = SenseId, Sentence = Sentence ?? new MultiString(), Translation = Translation ?? new MultiString(), - Reference = Reference + Reference = Reference, + DeletedAt = await context.IsObjectDeleted(SenseId) ? commit.DateTime : (DateTime?)null }; } - - public override async ValueTask ApplyChange(ExampleSentence entity, ChangeContext context) - { - if (Sentence is not null) entity.Sentence = Sentence; - if (Translation is not null) entity.Translation = Translation; - if (Reference is not null) entity.Reference = Reference; - if (await context.IsObjectDeleted(SenseId)) - { - entity.DeletedAt = context.Commit.DateTime; - } - } } diff --git a/backend/LcmCrdt/Changes/CreateSenseChange.cs b/backend/LcmCrdt/Changes/CreateSenseChange.cs index c643813f4..d5dcffde5 100644 --- a/backend/LcmCrdt/Changes/CreateSenseChange.cs +++ b/backend/LcmCrdt/Changes/CreateSenseChange.cs @@ -7,7 +7,7 @@ namespace LcmCrdt.Changes; -public class CreateSenseChange: Change, ISelfNamedType +public class CreateSenseChange: CreateChange, ISelfNamedType { public CreateSenseChange(MiniLcm.Sense sense, Guid entryId) : base(sense.Id == Guid.Empty ? Guid.NewGuid() : sense.Id) { @@ -31,7 +31,7 @@ private CreateSenseChange(Guid entityId, Guid entryId) : base(entityId) public string? PartOfSpeech { get; set; } public IList? SemanticDomain { get; set; } - public override IObjectBase NewEntity(Commit commit) + public override async ValueTask NewEntity(Commit commit, ChangeContext context) { return new Sense { @@ -40,19 +40,8 @@ public override IObjectBase NewEntity(Commit commit) Definition = Definition ?? new MultiString(), Gloss = Gloss ?? new MultiString(), PartOfSpeech = PartOfSpeech ?? string.Empty, - SemanticDomain = SemanticDomain ?? [] + SemanticDomain = SemanticDomain ?? [], + DeletedAt = await context.IsObjectDeleted(EntryId) ? commit.DateTime : (DateTime?)null }; } - - public override async ValueTask ApplyChange(Sense entity, ChangeContext context) - { - if (Definition is not null) entity.Definition = Definition; - if (Gloss is not null) entity.Gloss = Gloss; - if (PartOfSpeech is not null) entity.PartOfSpeech = PartOfSpeech; - if (SemanticDomain is not null) entity.SemanticDomain = SemanticDomain; - if (await context.IsObjectDeleted(EntryId)) - { - entity.DeletedAt = context.Commit.DateTime; - } - } } diff --git a/backend/LcmCrdt/Changes/CreateWritingSystemChange.cs b/backend/LcmCrdt/Changes/CreateWritingSystemChange.cs index f5c4f018f..da04be22c 100644 --- a/backend/LcmCrdt/Changes/CreateWritingSystemChange.cs +++ b/backend/LcmCrdt/Changes/CreateWritingSystemChange.cs @@ -8,7 +8,7 @@ namespace LcmCrdt.Changes; -public class CreateWritingSystemChange : Change, ISelfNamedType +public class CreateWritingSystemChange : CreateChange, ISelfNamedType { public required WritingSystemId WsId { get; init; } public required string Name { get; init; } @@ -36,9 +36,9 @@ private CreateWritingSystemChange(Guid entityId) : base(entityId) { } - public override IObjectBase NewEntity(Commit commit) + public override ValueTask NewEntity(Commit commit, ChangeContext context) { - return new WritingSystem(EntityId) + return new(new WritingSystem(EntityId) { WsId = WsId, Name = Name, @@ -47,17 +47,6 @@ public override IObjectBase NewEntity(Commit commit) Exemplars = Exemplars, Type = Type, Order = Order - }; - } - - public override ValueTask ApplyChange(WritingSystem entity, ChangeContext context) - { - entity.Name = Name; - entity.Abbreviation = Abbreviation; - entity.Font = Font; - entity.Exemplars = Exemplars; - entity.Type = Type; - entity.Order = Order; - return ValueTask.CompletedTask; + }); } } diff --git a/backend/LcmCrdt/Changes/JsonPatchChange.cs b/backend/LcmCrdt/Changes/JsonPatchChange.cs index bcff666e1..393b4be56 100644 --- a/backend/LcmCrdt/Changes/JsonPatchChange.cs +++ b/backend/LcmCrdt/Changes/JsonPatchChange.cs @@ -9,7 +9,7 @@ namespace LcmCrdt.Changes; -public class JsonPatchChange : Change, IPolyType where T : class, IPolyType, IObjectBase +public class JsonPatchChange : EditChange, IPolyType where T : class, IPolyType, IObjectBase { public static string TypeName => "jsonPatch:" + T.TypeName; public JsonPatchChange(Guid entityId, Action> action) : base(entityId) @@ -31,11 +31,6 @@ public JsonPatchChange(Guid entityId, IJsonPatchDocument patchDocument, JsonSeri public JsonPatchDocument PatchDocument { get; } - public override IObjectBase NewEntity(Commit commit) - { - throw new Exception("Cannot create new entity from patch"); - } - public override ValueTask ApplyChange(T entity, ChangeContext context) { PatchDocument.ApplyTo(entity); diff --git a/backend/LcmCrdt/ProjectContext.cs b/backend/LcmCrdt/ProjectContext.cs index ad9b69e37..f5e1ed7d7 100644 --- a/backend/LcmCrdt/ProjectContext.cs +++ b/backend/LcmCrdt/ProjectContext.cs @@ -9,7 +9,7 @@ private sealed class ProjectHolder private static readonly AsyncLocal _projectHolder = new(); - public CrdtProject? Project + public virtual CrdtProject? Project { get => _projectHolder.Value?.Project; set diff --git a/backend/harmony b/backend/harmony index 13a24360c..ce8badb85 160000 --- a/backend/harmony +++ b/backend/harmony @@ -1 +1 @@ -Subproject commit 13a24360c1a984a160e11459a64bdb16c71c75a5 +Subproject commit ce8badb853756e350c91994e4d967bc46fee8a80