1package dag
2
3import (
4 "github.com/MichaelMure/git-bug/entities/identity"
5 "github.com/MichaelMure/git-bug/entity"
6)
7
8var _ Operation = &NoOpOperation[Snapshot]{}
9var _ entity.OperationDoesntChangeSnapshot = &NoOpOperation[Snapshot]{}
10
11// NoOpOperation is an operation that does not change the entity state. It can
12// however be used to store arbitrary metadata in the entity history, for example
13// to support a bridge feature.
14type NoOpOperation[SnapT Snapshot] struct {
15 OpBase
16}
17
18func NewNoOpOp[SnapT Snapshot](opType entity.OperationType, author identity.Interface, unixTime int64) *NoOpOperation[SnapT] {
19 return &NoOpOperation[SnapT]{
20 OpBase: NewOpBase(opType, author, unixTime),
21 }
22}
23
24func (op *NoOpOperation[SnapT]) Id() entity.Id {
25 return IdOperation(op, &op.OpBase)
26}
27
28func (op *NoOpOperation[SnapT]) Apply(snapshot SnapT) {
29 // Nothing to do
30}
31
32func (op *NoOpOperation[SnapT]) Validate() error {
33 if err := op.OpBase.Validate(op, op.OperationType); err != nil {
34 return err
35 }
36 return nil
37}
38
39func (op *NoOpOperation[SnapT]) DoesntChangeSnapshot() {}