packages feed

keiro-dsl-0.21.0.0: test/conformance-keyword-segments/Generated/KeywordSegments/ProjectionCatalog.hs

-- @generated by keiro-dsl 0.21.0.0 (language keiro-dsl 6) from projection-catalog keyword-segments; do not edit.
{-# LANGUAGE OverloadedStrings #-}
module Generated.KeywordSegments.ProjectionCatalog
  ( projectionCatalog
  , validatedProjectionCatalog
  , projectionCatalogInventory
  , projectionCatalogRegistrations
  , projectionCatalogAsyncRegistrations
  , projectionCatalogQuerySupplies
  , registerProjectionCatalog
  , validateCustomTypeWriterProjectionSet
  , validateCustomTypeRebuildRebuildGroupId
  , startValidateCustomTypeRebuildRebuild
  ) 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 KeywordSegments.ProjectionCatalog.ProjectionCatalogHoles qualified as Holes
import Generated.KeywordSegments.ValidateCustomType.ReadModel qualified as RMValidateCustomType

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

validateCustomTypeWriterProjectionSet :: Catalog.ProjectionSet Holes.ValidateCustomTypeWriterEvent
validateCustomTypeWriterProjectionSet =
  Catalog.ProjectionSet
    (must (Catalog.mkSourceId "all"))
    (Catalog.ProjectionDefinition
      (must (Catalog.mkProjectionId "validate_custom_type_writer"))
      (must (Catalog.mkRebuildGroupId "validate_custom_type_rebuild"))
      ((must (Catalog.mkTargetId "validate_custom_type_table")) :| [])
      (Catalog.Replayable (Catalog.ReplayAdapter Holes.decodeValidateCustomTypeWriterReplay Holes.applyValidateCustomTypeWriterReplay))
      (Catalog.AsyncHandler (AsyncProjection "validate-custom-type-writer-v1" "keyword-segments-validate-custom-type" "validate-custom-type-writer" Holes.applyValidateCustomTypeWriterLive Holes.validateCustomTypeWriterIdempotencyKey) (must (Catalog.mkSubscriptionId "validate-custom-type-writer")) (must (Catalog.mkDedupKeyId "validate-custom-type-writer-v1")) (must (Catalog.mkClaimSite "projection-owner validate_custom_type_writer async-handler")) :| [])
      (must (Catalog.mkClaimSite "projection-owner validate_custom_type_writer"))
      :| [])
    (must (Catalog.mkClaimSite "projection-owner validate_custom_type_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 "validate_custom_type_table")) (Catalog.QualifiedTable "billing" "validate_custom_type") Catalog.ClearBeforeReplay [] (must (Catalog.mkClaimSite "target validate_custom_type_table"))]
    [Catalog.RebuildGroupDeclaration (must (Catalog.mkRebuildGroupId "validate_custom_type_rebuild")) [(must (Catalog.mkTargetId "validate_custom_type_table"))] [] (must (Catalog.mkClaimSite "rebuild-group validate_custom_type_rebuild"))]
    []
    []
    [Catalog.SubscriptionDeclaration (must (Catalog.mkSubscriptionId "validate-custom-type-writer")) "validate-custom-type-writer" (must (Catalog.mkSourceId "all")) KirokuSubscription.FromBeginning (must (Catalog.mkClaimSite "projection-owner validate_custom_type_writer subscription"))]
    [Catalog.DedupKeyDeclaration (must (Catalog.mkDedupKeyId "validate-custom-type-writer-v1")) "validate-custom-type-writer-v1" (must (Catalog.mkClaimSite "projection-owner validate_custom_type_writer dedup"))]
    [Catalog.SomeQueryModelBinding (Catalog.QueryModelBinding (must (Catalog.mkQueryModelId "validate_custom_type")) RMValidateCustomType.validateCustomTypeReadModel (must (Catalog.mkRebuildGroupId "validate_custom_type_rebuild")) [(must (Catalog.mkTargetId "validate_custom_type_table"))] (must (Catalog.mkClaimSite "readmodel validate_custom_type")))]
    [Catalog.SomeProjectionSet validateCustomTypeWriterProjectionSet]

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

validateCustomTypeRebuildRebuildGroupId :: Catalog.RebuildGroupId
validateCustomTypeRebuildRebuildGroupId = (must (Catalog.mkRebuildGroupId "validate_custom_type_rebuild"))

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