diff options
Diffstat (limited to 'entity/dag/op_noop.go')
-rw-r--r-- | entity/dag/op_noop.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/entity/dag/op_noop.go b/entity/dag/op_noop.go new file mode 100644 index 00000000..2bc53578 --- /dev/null +++ b/entity/dag/op_noop.go @@ -0,0 +1,39 @@ +package dag + +import ( + "github.com/MichaelMure/git-bug/entity" + "github.com/MichaelMure/git-bug/identity" +) + +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() {} |