Restoring Facts

Users sometimes make mistakes. They should be able to undo a deletion. To allow this, create a new fact type that represents the restoration.

To restore a site, define a fact type that refers to the deletion of that site. It needs no additional parameters.

[FactType("Blog.Site.Restored")]
public record SiteRestored(SiteDeleted deleted) { }

Renderer.RenderTypes(typeof(SiteRestored))
%0 Blog.Site.Restored Blog.Site.Restored Blog.Site.Deleted Blog.Site.Deleted Blog.Site.Restored->Blog.Site.Deleted deleted Blog.Site Blog.Site Blog.Site.Deleted->Blog.Site site Jinaga.User Jinaga.User Blog.Site->Jinaga.User creator

Create an instance of this fact to indicate that the deletion should no longer take effect.

var siteRestored = await jinagaClient.Fact(new SiteRestored(siteDeleted));

jinagaClient.RenderFacts(siteRestored)
%0 eLG0D2gojV+51Ix80JNo2Uh4EQTKvjbZUq5JNrf9K5gSXEqRmi7LBSleOl09F/bWdrlWUgDkalEH847v83U7fA== Jinaga.User publicKey --- FAKE USER --- fRStq94kRaFpm+n+5BCGNRP7e7NOyihLThCOo0vRo+inA0LbPUbVkJsNJwcWCKIVb9lUylMwc7Bt2vfHTbicPg== Blog.Site createdAt 2024-05-18T20:32:02.... fRStq94kRaFpm+n+5BCGNRP7e7NOyihLThCOo0vRo+inA0LbPUbVkJsNJwcWCKIVb9lUylMwc7Bt2vfHTbicPg==->eLG0D2gojV+51Ix80JNo2Uh4EQTKvjbZUq5JNrf9K5gSXEqRmi7LBSleOl09F/bWdrlWUgDkalEH847v83U7fA== creator CA+OPep595TfpqNBdW2+BsECRIh1fPq1ylm8+sRFLlTT3RjUJ9O1T/qpblB/yqWS8ERB4Nbp5kRQmdDNem0Qmw== Blog.Site.Deleted deletedAt 2024-05-18T20:32:02.... CA+OPep595TfpqNBdW2+BsECRIh1fPq1ylm8+sRFLlTT3RjUJ9O1T/qpblB/yqWS8ERB4Nbp5kRQmdDNem0Qmw==->fRStq94kRaFpm+n+5BCGNRP7e7NOyihLThCOo0vRo+inA0LbPUbVkJsNJwcWCKIVb9lUylMwc7Bt2vfHTbicPg== site JlMZSFnOaeJ3OPlM3qIFfUXGllRqzkbzkeIfEb1vYP+7S8IXk+MLXf1hrmv6zk/1gBP8CaMhEegXO0AIo+o4dw== Blog.Site.Restored JlMZSFnOaeJ3OPlM3qIFfUXGllRqzkbzkeIfEb1vYP+7S8IXk+MLXf1hrmv6zk/1gBP8CaMhEegXO0AIo+o4dw==->CA+OPep595TfpqNBdW2+BsECRIh1fPq1ylm8+sRFLlTT3RjUJ9O1T/qpblB/yqWS8ERB4Nbp5kRQmdDNem0Qmw== deleted

As you might imagine, the specification doesn't honor this new fact yet.

sites = await jinagaClient.Query(sitesByUser, user);

sites.Count()
0

But if we filter the deletions to include only those that don't have a successor restore fact, then we get the desired behavior.

sitesByUser = Given<User>.Match((user, facts) =>
    from site in facts.OfType<Site>()
    where site.creator == user
    where !facts.Any<SiteDeleted>(
        sd => sd.site == site &&
        // Honor only the site deletion that have not been restored
        !facts.Any<SiteRestored>(sr => sr.deleted == sd))
    select site);

sites = await jinagaClient.Query(sitesByUser, user);

sites.Count()
1

Continue With

Mutable Properties

Jinaga is a product of Jinaga LLC.

Michael L Perry, President