aboutsummaryrefslogtreecommitdiffstats
path: root/entity/dag/operation.go
blob: 9fcc055be607c7a0c064a95e3d3d9affdc160b84 (plain) (blame)
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
package dag

import (
	"github.com/MichaelMure/git-bug/entity"
	"github.com/MichaelMure/git-bug/identity"
)

// Operation is a piece of data defining a change to reflect on the state of an Entity.
// What this Operation or Entity's state looks like is not of the resort of this package as it only deals with the
// data structure and storage.
type Operation interface {
	// Id return the Operation identifier
	// Some care need to be taken to define a correct Id derivation and enough entropy in the data used to avoid
	// collisions. Notably:
	// - the Id of the first Operation will be used as the Id of the Entity. Collision need to be avoided across Entities.
	// - collisions can also happen within the set of Operations of an Entity. Simple Operation might not have enough
	//   entropy to yield unique Ids.
	// A common way to derive an Id will be to use the DeriveId function on the serialized operation data.
	Id() entity.Id
	// Validate check if the Operation data is valid
	Validate() error

	Author() identity.Interface
}

type operationBase struct {
	author identity.Interface

	// Not serialized. Store the op's id in memory.
	id entity.Id
}