-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcqrs.go
73 lines (52 loc) · 2.66 KB
/
cqrs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package cqrs
import (
"github.com/moleculer-go/moleculer"
"github.com/moleculer-go/store"
)
type Transformer func(context moleculer.Context, params moleculer.Payload) moleculer.Payload
type ManyTransformer func(context moleculer.Context, params moleculer.Payload) []moleculer.Payload
type EventStorer interface {
Mixin() moleculer.Mixin
MapEvent(originEvent, persistentEvent string, extraParams ...map[string]interface{}) moleculer.Event
MapAction(actionName string, eventName string, extraParams ...map[string]interface{}) moleculer.Action
//try to move these to a interface just around snapshoter
// StartSnapshot(snapshotName string, aggregateMetadata map[string]interface{}) error
// CompleteSnapshot(snapshotName string) error
// FailSnapshot(snapshotName string) error
// PauseEvents() error
// StartEvents()
Name() string
}
//BackupStrategy function that backups the aggregate data
type BackupStrategy func(snapshotID string) error
//RestoreStrategy function that restores the aggregate data based on the snapshotID
type RestoreStrategy func(snapshotID string) error
//SnapshotStrategy factory function to create a snapshot strategy.
type SnapshotStrategy func(aggregateName string) (BackupStrategy, RestoreStrategy)
//type AggregateRestore func(aggregateName string) RestoreStrategy
type StoreFactory func(name string, cqrsFields, settings map[string]interface{}) store.Adapter
type EventMapping interface {
//From(eventName string) moleculer.Event
// Create 1 (one) aggregate record with the result (single payload) of the transformations.
Create(transformAction string) moleculer.Event
// Create multiple aggregate records with the result (list of payloads) of the transformations.
CreateMany(transformAction string) moleculer.Event
// Update an existing aggregate record if the result of the transformation has an id field,
// or creates a new aggregate record if no id is present.
Update(transformAction string) moleculer.Event
}
type Aggregator interface {
Mixin() moleculer.Mixin
// Snapshot configure the snapshot behaviour of the aggregate
Snapshot(eventStore string) Aggregator
//On starts a event mapping chain. It takes the event name and returns an
// EventMapping object, which is used to map the transformation actions and these methods
// return an moleculer.Event object.
// Example:
// On("user.created").Create("profile.userProfile") -> returns moleculer.Event :)
// this will listen for the event: user.created and it will use
// the action profile.userProfile to transform the user.created event payload,
// the result will used to create a single new record in the aggregate.
On(event string) EventMapping
}
type M map[string]interface{}