packages feed

keiro-dsl-0.18.0.0: test/conformance-structural-text-sets/Generated/StructuralTextSets/ProjectionCatalog.hs

-- @generated by keiro-dsl 0.18.0.0 (language keiro-dsl 6) from projection-catalog structural-text-sets; do not edit.
{-# LANGUAGE OverloadedStrings #-}
module Generated.StructuralTextSets.ProjectionCatalog
  ( projectionCatalog
  , validatedProjectionCatalog
  , projectionCatalogInventory
  , projectionCatalogRegistrations
  , projectionCatalogAsyncRegistrations
  , projectionCatalogQuerySupplies
  , registerProjectionCatalog
  , labelWriterProjectionSet
  , labelRebuildRebuildGroupId
  , startLabelRebuildRebuild
  ) 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 StructuralTextSets.ProjectionCatalog.ProjectionCatalogHoles qualified as Holes
import Generated.StructuralTextSets.LabelLookup.ReadModel qualified as RMLabelLookup

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

labelWriterProjectionSet :: Catalog.ProjectionSet Holes.LabelWriterEvent
labelWriterProjectionSet =
  Catalog.ProjectionSet
    (must (Catalog.mkSourceId "all"))
    (Catalog.ProjectionDefinition
      (must (Catalog.mkProjectionId "label_writer"))
      (must (Catalog.mkRebuildGroupId "label_rebuild"))
      ((must (Catalog.mkTargetId "label_table")) :| [])
      (Catalog.Replayable (Catalog.ReplayAdapter Holes.decodeLabelWriterReplay Holes.applyLabelWriterReplay))
      (Catalog.AsyncHandler (AsyncProjection "label-writer-v1" "structural-text-sets-label-lookup" "label-writer" Holes.applyLabelWriterLive Holes.labelWriterIdempotencyKey) (must (Catalog.mkSubscriptionId "label-writer")) (must (Catalog.mkDedupKeyId "label-writer-v1")) (must (Catalog.mkClaimSite "projection-owner label_writer async-handler")) :| [])
      (must (Catalog.mkClaimSite "projection-owner label_writer"))
      :| [])
    (must (Catalog.mkClaimSite "projection-owner label_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 "label_table")) (Catalog.QualifiedTable "public" "label_values") Catalog.ClearBeforeReplay [] (must (Catalog.mkClaimSite "target label_table"))]
    [Catalog.RebuildGroupDeclaration (must (Catalog.mkRebuildGroupId "label_rebuild")) [(must (Catalog.mkTargetId "label_table"))] [] (must (Catalog.mkClaimSite "rebuild-group label_rebuild"))]
    []
    []
    [Catalog.SubscriptionDeclaration (must (Catalog.mkSubscriptionId "label-writer")) "label-writer" (must (Catalog.mkSourceId "all")) KirokuSubscription.FromBeginning (must (Catalog.mkClaimSite "projection-owner label_writer subscription"))]
    [Catalog.DedupKeyDeclaration (must (Catalog.mkDedupKeyId "label-writer-v1")) "label-writer-v1" (must (Catalog.mkClaimSite "projection-owner label_writer dedup"))]
    [Catalog.SomeQueryModelBinding (Catalog.QueryModelBinding (must (Catalog.mkQueryModelId "label_lookup")) RMLabelLookup.labelLookupReadModel (must (Catalog.mkRebuildGroupId "label_rebuild")) [(must (Catalog.mkTargetId "label_table"))] (must (Catalog.mkClaimSite "readmodel label_lookup")))]
    [Catalog.SomeProjectionSet labelWriterProjectionSet]

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

labelRebuildRebuildGroupId :: Catalog.RebuildGroupId
labelRebuildRebuildGroupId = (must (Catalog.mkRebuildGroupId "label_rebuild"))

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