summaryrefslogtreecommitdiffstatshomepage
path: root/entity
diff options
context:
space:
mode:
Diffstat (limited to 'entity')
-rw-r--r--entity/dag/op_noop.go8
-rw-r--r--entity/dag/op_set_metadata.go8
-rw-r--r--entity/dag/op_set_metadata_test.go8
-rw-r--r--entity/dag/operation.go4
-rw-r--r--entity/entity.go8
-rw-r--r--entity/operations.go2
-rw-r--r--entity/snapshot.go11
7 files changed, 27 insertions, 22 deletions
diff --git a/entity/dag/op_noop.go b/entity/dag/op_noop.go
index d8a2a05a..e94b2edf 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 19176183..42749fda 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 591ce9b2..a06f89da 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 40bd7da8..5099ad80 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 9f523858..eb20e65b 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 fd88f033..76c42ce8 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 c6ea43fc..9dd109cf 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
}