Sign in

    thy1016/mooncmd/projection does not have a README file

    LiveProjection

    pub(all) struct LiveProjection[AggregateId, E] {
    view : Json
    last_version : Int
    projection : Projection[AggregateId, E]
    event_store :
    EventStore
    [AggregateId, E]
    aggregate_id : AggregateId
    }

    实时投影(内存视图 + 检查点;拉取刷新形——FR-MC-3 参考实现)。

    LiveProjection::checkpoint

    fn[AggregateId, E] LiveProjection::checkpoint(self : LiveProjection[AggregateId, E]) -> Int

    读检查点

    LiveProjection::get_view

    fn[AggregateId, E] LiveProjection::get_view(self : LiveProjection[AggregateId, E]) -> Json

    读视图

    LiveProjection::new

    fn[AggregateId, E] LiveProjection::new(aggregate_id : AggregateId, event_store :
    EventStore
    [AggregateId, E], projection : Projection[AggregateId, E], position : SubscriptionPosition) -> LiveProjection[AggregateId, E] raise
    EventStoreError

    构造:按订阅位置装载——拉取起始版本之后的事件,批量折入初始视图, 检查点 = 已折末事件版本(流空 = 起始版本)。

    LiveProjection::refresh

    fn[AggregateId, E] LiveProjection::refresh(self : LiveProjection[AggregateId, E]) -> Unit raise
    EventStoreError

    刷新:拉取检查点之后的事件,折入视图,推进检查点;流空 = no-op。

    PersistedProjection

    pub(all) struct PersistedProjection {
    conn :
    Connection

    table_name : String
    }

    SQLite 持久化投影落点(视图 + checkpoint;save 即 ack,load 即恢复—— 与 LiveProjection 组合 = 重启续跑)。

    PersistedProjection::load

    fn PersistedProjection::load(self : PersistedProjection, id : String) -> (Json, Int)? raise

    PersistedProjection::new

    PersistedProjection::save

    fn PersistedProjection::save(self : PersistedProjection, id : String, view : Json, version : Int) -> Unit raise

    Projection

    pub(all) struct Projection[AggregateId, E] {
    init : () -> Json
    apply : (Json,
    EventMessage
    [AggregateId, E]) -> Json
    apply_batch : (Json, Array[
    EventMessage
    [AggregateId, E]]) -> Json
    }

    投影器(记录型函数面,ADR-MC-003 同族):init 出初始视图, apply 单事件演化,apply_batch 批量折叠(缺省 = 逐事件 apply)。

    Projection::new

    fn[AggregateId, E] Projection::new(init : () -> Json, apply : (Json,
    EventMessage
    [AggregateId, E]) -> Json, apply_batch : (Json, Array[
    EventMessage
    [AggregateId, E]]) -> Json) -> Projection[AggregateId, E]

    SubscriptionPosition

    pub(all) enum SubscriptionPosition {
    Origin
    Current
    FromVersion(Int)
    }

    订阅位置(刷新起点语义)

    default_batch

    fn[AggregateId, E] default_batch(apply : (Json,
    EventMessage
    [AggregateId, E]) -> Json) -> ((Json, Array[
    EventMessage
    [AggregateId, E]]) -> Json)

    缺省批量折叠(逐事件 apply——多数投影够用;性能敏感可自定义)。

    Source Files