operation.go

 1package dag
 2
 3import (
 4	"github.com/MichaelMure/git-bug/entity"
 5	"github.com/MichaelMure/git-bug/identity"
 6)
 7
 8// Operation is a piece of data defining a change to reflect on the state of an Entity.
 9// What this Operation or Entity's state looks like is not of the resort of this package as it only deals with the
10// data structure and storage.
11type Operation interface {
12	// Id return the Operation identifier
13	// Some care need to be taken to define a correct Id derivation and enough entropy in the data used to avoid
14	// collisions. Notably:
15	// - the Id of the first Operation will be used as the Id of the Entity. Collision need to be avoided across Entities.
16	// - collisions can also happen within the set of Operations of an Entity. Simple Operation might not have enough
17	//   entropy to yield unique Ids.
18	// A common way to derive an Id will be to use the DeriveId function on the serialized operation data.
19	Id() entity.Id
20	// Validate check if the Operation data is valid
21	Validate() error
22
23	Author() identity.Interface
24}
25
26type operationBase struct {
27	author identity.Interface
28
29	// Not serialized. Store the op's id in memory.
30	id entity.Id
31}