packages feed

keiro-dsl-0.18.0.0: test/conformance-bare-containers/Generated/BareContainers/ProjectionCatalog.hs

-- @generated by keiro-dsl 0.18.0.0 (language keiro-dsl 6) from projection-catalog bare-containers; do not edit.
{-# LANGUAGE OverloadedStrings #-}
module Generated.BareContainers.ProjectionCatalog
  ( projectionCatalog
  , validatedProjectionCatalog
  , projectionCatalogInventory
  , projectionCatalogRegistrations
  , projectionCatalogAsyncRegistrations
  , projectionCatalogQuerySupplies
  , registerProjectionCatalog
  , bareWriterProjectionSet
  , bareRebuildRebuildGroupId
  , startBareRebuildRebuild
  ) 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 BareContainers.ProjectionCatalog.ProjectionCatalogHoles qualified as Holes
import Generated.BareContainers.BareLookup.ReadModel qualified as RMBareLookup

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

bareWriterProjectionSet :: Catalog.ProjectionSet Holes.BareWriterEvent
bareWriterProjectionSet =
  Catalog.ProjectionSet
    (must (Catalog.mkSourceId "all"))
    (Catalog.ProjectionDefinition
      (must (Catalog.mkProjectionId "bare_writer"))
      (must (Catalog.mkRebuildGroupId "bare_rebuild"))
      ((must (Catalog.mkTargetId "bare_table")) :| [])
      (Catalog.Replayable (Catalog.ReplayAdapter Holes.decodeBareWriterReplay Holes.applyBareWriterReplay))
      (Catalog.AsyncHandler (AsyncProjection "bare-writer-v1" "bare-containers-bare-lookup" "bare-writer" Holes.applyBareWriterLive Holes.bareWriterIdempotencyKey) (must (Catalog.mkSubscriptionId "bare-writer")) (must (Catalog.mkDedupKeyId "bare-writer-v1")) (must (Catalog.mkClaimSite "projection-owner bare_writer async-handler")) :| [])
      (must (Catalog.mkClaimSite "projection-owner bare_writer"))
      :| [])
    (must (Catalog.mkClaimSite "projection-owner bare_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 "bare_table")) (Catalog.QualifiedTable "public" "bare_values") Catalog.ClearBeforeReplay [] (must (Catalog.mkClaimSite "target bare_table"))]
    [Catalog.RebuildGroupDeclaration (must (Catalog.mkRebuildGroupId "bare_rebuild")) [(must (Catalog.mkTargetId "bare_table"))] [] (must (Catalog.mkClaimSite "rebuild-group bare_rebuild"))]
    []
    []
    [Catalog.SubscriptionDeclaration (must (Catalog.mkSubscriptionId "bare-writer")) "bare-writer" (must (Catalog.mkSourceId "all")) KirokuSubscription.FromBeginning (must (Catalog.mkClaimSite "projection-owner bare_writer subscription"))]
    [Catalog.DedupKeyDeclaration (must (Catalog.mkDedupKeyId "bare-writer-v1")) "bare-writer-v1" (must (Catalog.mkClaimSite "projection-owner bare_writer dedup"))]
    [Catalog.SomeQueryModelBinding (Catalog.QueryModelBinding (must (Catalog.mkQueryModelId "bare_lookup")) RMBareLookup.bareLookupReadModel (must (Catalog.mkRebuildGroupId "bare_rebuild")) [(must (Catalog.mkTargetId "bare_table"))] (must (Catalog.mkClaimSite "readmodel bare_lookup")))]
    [Catalog.SomeProjectionSet bareWriterProjectionSet]

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

bareRebuildRebuildGroupId :: Catalog.RebuildGroupId
bareRebuildRebuildGroupId = (must (Catalog.mkRebuildGroupId "bare_rebuild"))

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