diff --git a/entities/bug/bug.go b/entities/bug/bug.go index ab873ed8f635cb97e1b4759d1f27b9bced56a9b0..6c440433bd9c23b21afcc56495ea681c24b1e915 100644 --- a/entities/bug/bug.go +++ b/entities/bug/bug.go @@ -13,7 +13,7 @@ import ( ) var _ Interface = &Bug{} -var _ entity.Interface[*Snapshot, Operation] = &Bug{} +var _ entity.Interface[Operation, *Snapshot] = &Bug{} // 1: original format // 2: no more legacy identities @@ -34,7 +34,7 @@ var def = dag.Definition{ var ClockLoader = dag.ClockLoader(def) type Interface interface { - entity.Interface[*Snapshot, Operation] + entity.Interface[Operation, *Snapshot] } // Bug holds the data of a bug thread, organized in a way close to diff --git a/entities/bug/op_add_comment.go b/entities/bug/op_add_comment.go index 17cc5dd0575ab8f7496c075009832e851a296b70..267fe731ea77dc99da728718ef330c1bb8526839 100644 --- a/entities/bug/op_add_comment.go +++ b/entities/bug/op_add_comment.go @@ -12,6 +12,7 @@ import ( ) var _ Operation = &AddCommentOperation{} +var _ dag.Operation = &AddCommentOperation{} var _ entity.OperationWithFiles = &AddCommentOperation{} // AddCommentOperation will add a new comment in the bug diff --git a/entities/bug/snapshot.go b/entities/bug/snapshot.go index 9dbc78625b09ec2174c1bbb3d1812f94c4d152ab..32baf42c15b99fb17eeb0f903d31a9f068195576 100644 --- a/entities/bug/snapshot.go +++ b/entities/bug/snapshot.go @@ -9,7 +9,7 @@ import ( "github.com/MichaelMure/git-bug/entity" ) -var _ entity.Snapshot = &Snapshot{} +// var _ entity.Snapshot = &Snapshot{} // Snapshot is a compiled form of the Bug data structure used for storage and merge type Snapshot struct { @@ -26,7 +26,7 @@ type Snapshot struct { Timeline []TimelineItem - Operations []entity.Operation + Operations []Operation } // Id returns the Bug identifier @@ -38,11 +38,11 @@ func (snap *Snapshot) Id() entity.Id { return snap.id } -func (snap *Snapshot) AllOperations() []entity.Operation { +func (snap *Snapshot) AllOperations() []Operation { return snap.Operations } -func (snap *Snapshot) AppendOperation(op entity.Operation) { +func (snap *Snapshot) AppendOperation(op Operation) { snap.Operations = append(snap.Operations, op) } diff --git a/entity/dag/op_noop.go b/entity/dag/op_noop.go index d8a2a05aa988435c560636efdc7f6ba825b48ffc..e94b2edfaf6f0a0c28c1626f3396e674fa98979f 100644 --- a/entity/dag/op_noop.go +++ b/entity/dag/op_noop.go @@ -5,17 +5,17 @@ import ( "github.com/MichaelMure/git-bug/entity" ) -var _ Operation = &NoOpOperation[entity.Snapshot]{} -var _ entity.OperationDoesntChangeSnapshot = &NoOpOperation[entity.Snapshot]{} +var _ Operation = &NoOpOperation[Snapshot]{} +var _ entity.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 entity.Snapshot] struct { +type NoOpOperation[SnapT Snapshot] struct { OpBase } -func NewNoOpOp[SnapT entity.Snapshot](opType entity.OperationType, author identity.Interface, unixTime int64) *NoOpOperation[SnapT] { +func NewNoOpOp[SnapT Snapshot](opType entity.OperationType, author identity.Interface, unixTime int64) *NoOpOperation[SnapT] { return &NoOpOperation[SnapT]{ OpBase: NewOpBase(opType, author, unixTime), } diff --git a/entity/dag/op_set_metadata.go b/entity/dag/op_set_metadata.go index 191761836d44f38ce2cf661a1f2cb0d57bdba960..42749fda669740f7608e15edbcc02d8254bf5d27 100644 --- a/entity/dag/op_set_metadata.go +++ b/entity/dag/op_set_metadata.go @@ -10,16 +10,16 @@ import ( "github.com/MichaelMure/git-bug/util/text" ) -var _ Operation = &SetMetadataOperation[entity.Snapshot]{} -var _ entity.OperationDoesntChangeSnapshot = &SetMetadataOperation[entity.Snapshot]{} +var _ Operation = &SetMetadataOperation[Snapshot]{} +var _ entity.OperationDoesntChangeSnapshot = &SetMetadataOperation[Snapshot]{} -type SetMetadataOperation[SnapT entity.Snapshot] struct { +type SetMetadataOperation[SnapT Snapshot] struct { OpBase Target entity.Id `json:"target"` NewMetadata map[string]string `json:"new_metadata"` } -func NewSetMetadataOp[SnapT entity.Snapshot](opType entity.OperationType, author identity.Interface, unixTime int64, target entity.Id, newMetadata map[string]string) *SetMetadataOperation[SnapT] { +func NewSetMetadataOp[SnapT Snapshot](opType entity.OperationType, author identity.Interface, unixTime int64, target entity.Id, newMetadata map[string]string) *SetMetadataOperation[SnapT] { return &SetMetadataOperation[SnapT]{ OpBase: NewOpBase(opType, author, unixTime), Target: target, diff --git a/entity/dag/op_set_metadata_test.go b/entity/dag/op_set_metadata_test.go index 591ce9b27b248846d60b185e15021fdef0e3ca5f..a06f89daf9fb59f2dac106fa8efa8513a24361f1 100644 --- a/entity/dag/op_set_metadata_test.go +++ b/entity/dag/op_set_metadata_test.go @@ -12,17 +12,17 @@ import ( "github.com/stretchr/testify/require" ) -var _ entity.Snapshot = &snapshotMock{} +var _ Snapshot = &snapshotMock{} type snapshotMock struct { - ops []entity.Operation + ops []Operation } -func (s *snapshotMock) AllOperations() []entity.Operation { +func (s *snapshotMock) AllOperations() []Operation { return s.ops } -func (s *snapshotMock) AppendOperation(op entity.Operation) { +func (s *snapshotMock) AppendOperation(op Operation) { s.ops = append(s.ops, op) } diff --git a/entity/dag/operation.go b/entity/dag/operation.go index 40bd7da8d86c9d68107f7575049e8456a7e3a11a..5099ad805cb50a505fdcb1e3e5921562d3e28bb7 100644 --- a/entity/dag/operation.go +++ b/entity/dag/operation.go @@ -12,6 +12,8 @@ import ( "github.com/MichaelMure/git-bug/entity" ) +type Snapshot entity.SnapshotT[Operation] + // Operation is an extended interface for an entity.Operation working with the dag package. type Operation interface { entity.Operation @@ -24,7 +26,7 @@ type Operation interface { setExtraMetadataImmutable(key string, value string) } -type OperationWithApply[SnapT entity.Snapshot] interface { +type OperationWithApply[SnapT Snapshot] interface { Operation // Apply the operation to a Snapshot to create the final state diff --git a/entity/entity.go b/entity/entity.go index 9f5238584792a8fe754678bf5bb5178d4824a7ab..eb20e65b12c735e5e1cd378b16c8fc20b7948686 100644 --- a/entity/entity.go +++ b/entity/entity.go @@ -9,9 +9,9 @@ import ( type Bare bootstrap.Entity // Interface define the extended interface of an Entity -type Interface[SnapT Snapshot, OpT Operation] interface { +type Interface[OpT Operation, SnapT Snapshot] interface { Bare - CompileToSnapshot[SnapT] + CompileToSnapshot[OpT, SnapT] // Validate checks if the Entity data is valid Validate() error @@ -36,8 +36,8 @@ type Interface[SnapT Snapshot, OpT Operation] interface { EditLamportTime() lamport.Time } -type WithCommit[SnapT Snapshot, OpT Operation] interface { - Interface[SnapT, OpT] +type WithCommit[OpT Operation, SnapT Snapshot] interface { + Interface[OpT, SnapT] Committer } diff --git a/entity/operations.go b/entity/operations.go index fd88f033cac7ec895c3e0f3db47e4e53ba3abf3c..76c42ce8ea298fcfae58b5078dcbd960af1cf2dc 100644 --- a/entity/operations.go +++ b/entity/operations.go @@ -50,7 +50,7 @@ type Operation interface { AllMetadata() map[string]string } -type OperationWithApply[SnapT Snapshot] interface { +type OperationWithApply[OpT Operation, SnapT Snapshot] interface { Operation // Apply the operation to a Snapshot to create the final state diff --git a/entity/snapshot.go b/entity/snapshot.go index c6ea43fc7f0adfd0f22bab2f86da66f48641cd72..9dd109cf2473614af71bae34789bec36c826ab67 100644 --- a/entity/snapshot.go +++ b/entity/snapshot.go @@ -1,14 +1,17 @@ package entity // Snapshot is the minimal interface that a snapshot need to implement -type Snapshot interface { +type Snapshot SnapshotT[Operation] + +// SnapshotT is the minimal interface that a snapshot need to implement +type SnapshotT[OpT Operation] interface { // AllOperations returns all the operations that have been applied to that snapshot, in order - AllOperations() []Operation + AllOperations() []OpT // AppendOperation add an operation in the list - AppendOperation(op Operation) + AppendOperation(op OpT) } -type CompileToSnapshot[SnapT Snapshot] interface { +type CompileToSnapshot[OpT Operation, SnapT Snapshot] interface { // Compile an Entity in an easily usable snapshot Compile() SnapT }