packages feed

keiro-dsl-0.17.0.0: test/conformance-structural-nominals/Generated/StructuralNominalLeaves/ProjectionCatalog.hs

-- @generated by keiro-dsl 0.17.0.0 (language keiro-dsl 6) from projection-catalog structural-nominal-leaves; do not edit.
{-# LANGUAGE OverloadedStrings #-}
module Generated.StructuralNominalLeaves.ProjectionCatalog
  ( projectionCatalog
  , validatedProjectionCatalog
  , projectionCatalogInventory
  , projectionCatalogRegistrations
  , projectionCatalogAsyncRegistrations
  , projectionCatalogQuerySupplies
  , registerProjectionCatalog
  , templateWriterProjectionSet
  , templateRebuildRebuildGroupId
  , startTemplateRebuildRebuild
  ) where

import Data.List.NonEmpty (NonEmpty (..))
import Effectful (Eff, IOE, (:>))
import Keiro.Projection (AsyncProjection (..))
import Keiro.Projection.Catalog qualified as Catalog
import Keiro.ReadModel.Rebuild qualified as Rebuild
import Kiroku.Store.Effect (Store)
import Kiroku.Store.Subscription.Types qualified as KirokuSubscription
import StructuralNominalLeaves.ProjectionCatalog.ProjectionCatalogHoles qualified as Holes
import Generated.StructuralNominalLeaves.TemplateLookup.ReadModel qualified as RMTemplateLookup

must :: Show error => Either error value -> value
must = either (error . show) id

templateWriterProjectionSet :: Catalog.ProjectionSet Holes.TemplateWriterEvent
templateWriterProjectionSet =
  Catalog.ProjectionSet
    (must (Catalog.mkSourceId "all"))
    (Catalog.ProjectionDefinition
      (must (Catalog.mkProjectionId "template_writer"))
      (must (Catalog.mkRebuildGroupId "template_rebuild"))
      ((must (Catalog.mkTargetId "template_table")) :| [])
      (Catalog.Replayable (Catalog.ReplayAdapter Holes.decodeTemplateWriterReplay Holes.applyTemplateWriterReplay))
      (Catalog.AsyncHandler (AsyncProjection "template-writer-v1" "structural-nominal-leaves-template-lookup" "template-writer" Holes.applyTemplateWriterLive Holes.templateWriterIdempotencyKey) (must (Catalog.mkSubscriptionId "template-writer")) (must (Catalog.mkDedupKeyId "template-writer-v1")) (must (Catalog.mkClaimSite "projection-owner template_writer async-handler")) :| [])
      (must (Catalog.mkClaimSite "projection-owner template_writer"))
      :| [])
    (must (Catalog.mkClaimSite "projection-owner template_writer source"))

projectionCatalog :: Catalog.ProjectionCatalog
projectionCatalog =
  Catalog.ProjectionCatalog
    [Catalog.SourceDeclaration (must (Catalog.mkSourceId "all")) Catalog.AllStreams "all-streams/generated-codec/v1" (must (Catalog.mkClaimSite "source all"))]
    [Catalog.TargetDeclaration (must (Catalog.mkTargetId "template_table")) (Catalog.QualifiedTable "public" "templates") Catalog.ClearBeforeReplay [] (must (Catalog.mkClaimSite "target template_table"))]
    [Catalog.RebuildGroupDeclaration (must (Catalog.mkRebuildGroupId "template_rebuild")) [(must (Catalog.mkTargetId "template_table"))] [] (must (Catalog.mkClaimSite "rebuild-group template_rebuild"))]
    []
    []
    [Catalog.SubscriptionDeclaration (must (Catalog.mkSubscriptionId "template-writer")) "template-writer" (must (Catalog.mkSourceId "all")) KirokuSubscription.FromBeginning (must (Catalog.mkClaimSite "projection-owner template_writer subscription"))]
    [Catalog.DedupKeyDeclaration (must (Catalog.mkDedupKeyId "template-writer-v1")) "template-writer-v1" (must (Catalog.mkClaimSite "projection-owner template_writer dedup"))]
    [Catalog.SomeQueryModelBinding (Catalog.QueryModelBinding (must (Catalog.mkQueryModelId "template_lookup")) RMTemplateLookup.templateLookupReadModel (must (Catalog.mkRebuildGroupId "template_rebuild")) [(must (Catalog.mkTargetId "template_table"))] (must (Catalog.mkClaimSite "readmodel template_lookup")))]
    [Catalog.SomeProjectionSet templateWriterProjectionSet]

validatedProjectionCatalog :: Catalog.ValidatedProjectionCatalog
validatedProjectionCatalog = case Catalog.validateProjectionCatalog projectionCatalog of
  Catalog.Success catalog -> catalog
  Catalog.Failure diagnostics -> error ("keiro-dsl generated an invalid projection catalog: " <> show diagnostics)

projectionCatalogInventory :: Catalog.CatalogInventory
projectionCatalogInventory = Catalog.catalogInventory validatedProjectionCatalog

projectionCatalogRegistrations :: [Catalog.CatalogRegistration]
projectionCatalogRegistrations = Catalog.catalogRegistrations validatedProjectionCatalog

projectionCatalogAsyncRegistrations :: [Catalog.AsyncProjectionRegistration]
projectionCatalogAsyncRegistrations = Catalog.asyncProjectionRegistrations validatedProjectionCatalog

projectionCatalogQuerySupplies :: [Catalog.ResolvedQuerySupply]
projectionCatalogQuerySupplies = Catalog.resolvedQuerySupplies validatedProjectionCatalog

registerProjectionCatalog :: (Store :> es) => Eff es (Either Rebuild.CatalogRegistrationError [Rebuild.GroupRebuildMetadata])
registerProjectionCatalog = Rebuild.registerProjectionCatalog validatedProjectionCatalog

templateRebuildRebuildGroupId :: Catalog.RebuildGroupId
templateRebuildRebuildGroupId = (must (Catalog.mkRebuildGroupId "template_rebuild"))

startTemplateRebuildRebuild :: (IOE :> es, Store :> es) => Rebuild.RebuildOptions -> Eff es (Either Rebuild.CatalogRebuildError Rebuild.RebuildRunReport)
startTemplateRebuildRebuild = Rebuild.startCatalogRebuild validatedProjectionCatalog templateRebuildRebuildGroupId