1package entity
2
3import (
4 bootstrap "github.com/MichaelMure/git-bug/entity/boostrap"
5 "github.com/MichaelMure/git-bug/repository"
6 "github.com/MichaelMure/git-bug/util/lamport"
7)
8
9type Bare bootstrap.Entity
10
11// Interface define the extended interface of an Entity
12type Interface[OpT Operation, SnapT Snapshot] interface {
13 Bare
14 CompileToSnapshot[OpT, SnapT]
15
16 // Validate checks if the Entity data is valid
17 Validate() error
18
19 // Append an operation into the staging area, to be committed later
20 Append(op OpT)
21
22 // Operations returns the ordered operations
23 Operations() []OpT
24
25 // FirstOp lookup for the very first operation of the Entity.
26 FirstOp() OpT
27
28 // // LastOp lookup for the very last operation of the Entity.
29 // // For a valid Entity, should never be nil
30 // LastOp() OpT
31
32 // CreateLamportTime return the Lamport time of creation
33 CreateLamportTime() lamport.Time
34
35 // EditLamportTime return the Lamport time of the last edit
36 EditLamportTime() lamport.Time
37}
38
39type WithCommit[OpT Operation, SnapT Snapshot] interface {
40 Interface[OpT, SnapT]
41 Committer
42}
43
44type Committer interface {
45 // NeedCommit indicates that the in-memory state changed and need to be committed in the repository
46 NeedCommit() bool
47
48 // Commit writes the staging area in Git and move the operations to the packs
49 Commit(repo repository.ClockedRepo) error
50
51 // CommitAsNeeded execute a Commit only if necessary. This function is useful to avoid getting an error if the Entity
52 // is already in sync with the repository.
53 CommitAsNeeded(repo repository.ClockedRepo) error
54}