Deleting Facts

Facts are not truly deleted. You indicate that they should be deleted by introducing a new fact. There are mechanisms for taking them out of storage, but we'll cover those later.

To indicate that a site should be deleted, define a fact that refers to the site as a predecessor. It also should have a timestamp so that we can differentiate one deletion from another.

[FactType("Blog.Site.Deleted")]
public record SiteDeleted(Site site, DateTime deletedAt) { }

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

To indicate that a site should be deleted, create an instance of that fact.

var siteDeleted = await jinagaClient.Fact(new SiteDeleted(site, DateTime.UtcNow));

jinagaClient.RenderFacts(siteDeleted)
%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

If you query the specification now, you will still see the site.

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

sites.Count()
1

That's because we need to change the specification to exclude deleted sites. Add a clause that filters out sites that have a site deleted successor.

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

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

sites.Count()
0

Continue With

Restoring Facts

Jinaga is a product of Jinaga LLC.

Michael L Perry, President