0.12.5 • Published 2 years ago

wechaty-cqrs v0.12.5

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 years ago

CQRS Wechaty

NPM Version NPM Ducksify Extension ES Modules

A event-driven architecture wrapper for Wechaty that applies the CQS principle by using separate Query and Command messages to retrieve and modify the bot state, respectively.

Command Query Responsibility Segregation (CQRS) Wechaty

Image source: Introducing Derivative Event Sourcing

Command Query Responsibility Separation (CQRS)

Command query responsibility separation (CQRS) generalises CQS to message-driven and event-driven architectures: it applies the CQS principle by using separate Query and Command messages to retrieve and modify data, respectively.

Wikipedia: Command–query separation

Command Query Responsibility Segregation (CQRS) Pattern

Image source: CQRS (command query responsibility segregation)

Usage

Install

npm install wechaty-cqrs wechaty

Quick start

Here's the CQRS version of the Wechaty ding/dong bot:

import * as WECHATY from 'wechaty'
import * as CQRS    from 'wechaty-cqrs'

import { filter }   from 'rxjs/operators'

const wechaty = WECHATY.WechatyBuilder.build()
await wechaty.init()

const bus$ = CQRS.bus(wechaty)

bus$.pipe(
  filter(CQRS.isActionOf(CQRS.events.messageReceivedEvent)),
  filter(event => event.payloads.type === CQRS.sayable.type.Text),
  filter(event => event.payloads.payload === 'ding')
).subscribe(ding => bus$.next(
  CQRS.commands.sendMessage(
    ding.payload.talkerId,
    CQRS.sayable.text('dong'),
  ),
))

await wechaty.start()

Diagrams

CQRS Events Structure

graph LR
  classDef event fill:DarkGoldenRod
  classDef command fill:blue
  classDef query fill:green

  subgraph Command
    C(VerbNounCommand):::command
  end

  subgraph Message
    MC(NounVerbedMessage)
    MQ(NounGotMessage)
  end
    
  subgraph Query
    Q(GetNounQuery):::query
  end

  subgraph Event
    ER(ReceivedEvent):::event
  end

  C-->MC

  ER-->ER

  Q-->MQ

Command

sequenceDiagram
    participant Bus
    participant Redux
    participant Wechaty

    Bus->>Redux: ExecuteCommand
    Redux->>Wechaty: Call
    Wechaty->>Redux: Call Return (void)
    Redux->>Bus: CommandExecutedMessage

Query

sequenceDiagram
    participant Bus
    participant Redux
    participant Wechaty

    Bus->>Redux: GetNounQuery
    Redux->>Wechaty: Call
    Wechaty->>Redux: Call Return (value)
    Redux->>Bus: NounGotMessage

Event

sequenceDiagram
    participant Bus
    participant Redux
    participant Wechaty

    Wechaty->>Redux: ReceivedEvent
    Redux->>Bus: ReceivedEvent

API Docs

TBW

Resources

  • class-transformer - Decorator-based transformation, serialization, and deserialization between objects and classes.

History

main v0.1 (Mar 11, 2022)

Unit tests all passed, DevOps enabled.

v0.0.1 (Mar 6, 2022)

Init README & Draft design.

Author

Huan LI (李卓桓), Microsoft Regional Director, zixia@zixia.net

Profile of Huan LI (李卓桓) on StackOverflow

Copyright & License

  • Code & Docs © 2022 Huan (李卓桓) \zixia@zixia.net\
  • Code released under the Apache-2.0 License
  • Docs released under Creative Commons
0.15.4

2 years ago

0.13.6

2 years ago

0.13.7

2 years ago

0.13.8

2 years ago

0.13.9

2 years ago

0.13.1

2 years ago

0.13.2

2 years ago

0.13.3

2 years ago

0.15.2

2 years ago

0.13.4

2 years ago

0.15.3

2 years ago

0.13.5

2 years ago

0.13.12

2 years ago

0.13.11

2 years ago

0.13.16

2 years ago

0.13.15

2 years ago

0.13.14

2 years ago

0.9.2

2 years ago

0.7.4

2 years ago

0.13.13

2 years ago

0.9.1

2 years ago

0.7.3

2 years ago

0.13.19

2 years ago

0.3.1

2 years ago

0.1.3

2 years ago

0.13.18

2 years ago

0.5.2

2 years ago

0.3.4

2 years ago

0.13.17

2 years ago

0.5.1

2 years ago

0.3.3

2 years ago

0.13.23

2 years ago

0.13.22

2 years ago

0.9.3

2 years ago

0.7.5

2 years ago

0.13.21

2 years ago

0.10.1

2 years ago

0.10.2

2 years ago

0.12.1

2 years ago

0.10.3

2 years ago

0.12.2

2 years ago

0.10.4

2 years ago

0.12.3

2 years ago

0.12.4

2 years ago

0.12.5

2 years ago

0.2.1

2 years ago

0.6.3

2 years ago

0.6.2

2 years ago

0.6.5

2 years ago

0.6.4

2 years ago

0.6.1

2 years ago

0.0.1

2 years ago