aboutsummaryrefslogtreecommitdiffstats
path: root/entity/dag/op_noop.go
blob: c2d896a644d96902b5b9f849d0a901bfbce198f9 (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
32
33
34
35
36
37
38
39
package dag

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

var _ Operation = &NoOpOperation[Snapshot]{}
var _ OperationDoesntChangeSnapshot = &NoOpOperation[Snapshot]{}

// NoOpOperation is an operation that does not change the entity state. It can
// however be used to store arbitrary metadata in the entity history, for example
// to support a bridge feature.
type NoOpOperation[SnapT Snapshot] struct {
	OpBase
}

func NewNoOpOp[SnapT Snapshot](opType OperationType, author identity.Interface, unixTime int64) *NoOpOperation[SnapT] {
	return &NoOpOperation[SnapT]{
		OpBase: NewOpBase(opType, author, unixTime),
	}
}

func (op *NoOpOperation[SnapT]) Id() entity.Id {
	return IdOperation(op, &op.OpBase)
}

func (op *NoOpOperation[SnapT]) Apply(snapshot SnapT) {
	// Nothing to do
}

func (op *NoOpOperation[SnapT]) Validate() error {
	if err := op.OpBase.Validate(op, op.OperationType); err != nil {
		return err
	}
	return nil
}

func (op *NoOpOperation[SnapT]) DoesntChangeSnapshot() {}