Documentation ¶
Index ¶
- Constants
- func IsErrMultipleMatch(err error) bool
- func Resolve[T Interface](rs Resolvers, id Id) (T, error)
- func SeparateIds(prefix string) (primaryPrefix string, secondaryPrefix string)
- type CachedResolver
- type CombinedId
- func (ci CombinedId) HasPrefix(prefix string) bool
- func (ci CombinedId) Human() string
- func (ci CombinedId) MarshalGQL(w io.Writer)
- func (ci CombinedId) PrimaryPrefix() string
- func (ci CombinedId) SecondaryPrefix() string
- func (ci CombinedId) String() string
- func (ci *CombinedId) UnmarshalGQL(v interface{}) error
- func (ci CombinedId) Validate() error
- type ErrInvalidFormat
- type ErrMultipleMatch
- type Id
- type Interface
- type MergeResult
- type MergeStatus
- type Resolver
- type ResolverFunc
- type Resolvers
Constants ¶
const UnsetCombinedId = CombinedId("unset")
const UnsetId = Id("unset")
Variables ¶
This section is empty.
Functions ¶
func IsErrMultipleMatch ¶
func Resolve ¶ added in v0.8.0
Resolve use the appropriate sub-resolver for the given type and find the Entity matching the Id.
func SeparateIds ¶ added in v0.8.0
SeparateIds extract primary and secondary prefix from an arbitrary length prefix of an Id created with CombineIds.
Types ¶
type CachedResolver ¶ added in v0.8.0
type CachedResolver struct {
// contains filtered or unexported fields
}
CachedResolver is a resolver ensuring that loading is done only once through another Resolver.
func NewCachedResolver ¶ added in v0.8.0
func NewCachedResolver(resolver Resolver) *CachedResolver
type CombinedId ¶ added in v0.8.0
type CombinedId string
CombinedId is an Id holding information from both a primary Id and a secondary Id. While it looks like a regular Id, do not just cast from one to another. Instead, use CombineIds and SeparateIds to create it and split it.
func CombineIds ¶ added in v0.8.0
func CombineIds(primary Id, secondary Id) CombinedId
CombineIds compute a merged Id holding information from both the primary Id and the secondary Id.
This allows to later find efficiently a secondary element because we can access the primary one directly instead of searching for a primary that has a secondary matching the Id.
An example usage is Comment in a Bug. The interleaved Id will hold part of the Bug Id and part of the Comment Id.
To allow the use of an arbitrary length prefix of this Id, Ids from primary and secondary are interleaved with this irregular pattern to give the best chance to find the secondary even with a 7 character prefix.
Format is: PSPSPSPPPSPPPPSPPPPSPPPPSPPPPSPPPPSPPPPSPPPPSPPPPSPPPPSPPPPSPPPP
A complete interleaved Id hold 50 characters for the primary and 14 for the secondary, which give a key space of 36^50 for the primary (~6 * 10^77) and 36^14 for the secondary (~6 * 10^21). This asymmetry assumes a reasonable number of secondary within a primary Entity, while still allowing for a vast key space for the primary (that is, a globally merged database) with a low risk of collision.
Here is the breakdown of several common prefix length:
5: 3P, 2S 7: 4P, 3S 10: 6P, 4S 16: 11P, 5S
func (CombinedId) HasPrefix ¶ added in v0.8.0
func (ci CombinedId) HasPrefix(prefix string) bool
func (CombinedId) Human ¶ added in v0.8.0
func (ci CombinedId) Human() string
Human return the identifier, shortened for human consumption
func (CombinedId) MarshalGQL ¶ added in v0.8.0
func (ci CombinedId) MarshalGQL(w io.Writer)
MarshalGQL implement the Marshaler interface for gqlgen
func (CombinedId) PrimaryPrefix ¶ added in v0.8.0
func (ci CombinedId) PrimaryPrefix() string
PrimaryPrefix is a helper to extract the primary prefix. If practical, use SeparateIds instead.
func (CombinedId) SecondaryPrefix ¶ added in v0.8.0
func (ci CombinedId) SecondaryPrefix() string
SecondaryPrefix is a helper to extract the secondary prefix. If practical, use SeparateIds instead.
func (CombinedId) String ¶ added in v0.8.0
func (ci CombinedId) String() string
String return the identifier as a string
func (*CombinedId) UnmarshalGQL ¶ added in v0.8.0
func (ci *CombinedId) UnmarshalGQL(v interface{}) error
UnmarshalGQL implement the Unmarshaler interface for gqlgen
func (CombinedId) Validate ¶ added in v0.8.0
func (ci CombinedId) Validate() error
Validate tell if the Id is valid
type ErrInvalidFormat ¶ added in v0.8.0
type ErrInvalidFormat struct {
// contains filtered or unexported fields
}
func NewErrInvalidFormat ¶ added in v0.8.0
func NewErrInvalidFormat(version uint, expected uint) *ErrInvalidFormat
func NewErrUnknownFormat ¶ added in v0.8.0
func NewErrUnknownFormat(expected uint) *ErrInvalidFormat
func (ErrInvalidFormat) Error ¶ added in v0.8.0
func (e ErrInvalidFormat) Error() string
type ErrMultipleMatch ¶
type ErrMultipleMatch struct { Matching []Id // contains filtered or unexported fields }
func NewErrMultipleMatch ¶
func NewErrMultipleMatch(entityType string, matching []Id) *ErrMultipleMatch
func (ErrMultipleMatch) Error ¶
func (e ErrMultipleMatch) Error() string
type Id ¶
type Id string
Id is an identifier for an entity or part of an entity
func DeriveId ¶ added in v0.8.0
DeriveId generate an Id from the serialization of the object or part of the object.
func RefToId ¶ added in v0.8.0
RefToId parse a git reference and return the corresponding Entity's Id.
func RefsToIds ¶ added in v0.8.0
RefsToIds parse a slice of git references and return the corresponding Entity's Id.
func (Id) MarshalGQL ¶
MarshalGQL implement the Marshaler interface for gqlgen
func (*Id) UnmarshalGQL ¶
UnmarshalGQL implement the Unmarshaler interface for gqlgen
type Interface ¶
type Interface interface { // Id return the Entity identifier // // This Id need to be immutable without having to store the entity somewhere (ie, an entity only in memory // should have a valid Id, and it should not change if further edit are done on this entity). // How to achieve that is up to the entity itself. A common way would be to take a hash of an immutable data at // the root of the entity. // It is acceptable to use such a hash and keep mutating that data as long as Id() is not called. Id() Id }
type MergeResult ¶
type MergeResult struct { // Err is set when a terminal error occur in the process Err error Id Id Status MergeStatus // Only set for Invalid status Reason string // Only set for New or Updated status Entity Interface }
MergeResult hold the result of a merge operation on an Entity.
func NewMergeError ¶
func NewMergeError(err error, id Id) MergeResult
func NewMergeInvalidStatus ¶
func NewMergeInvalidStatus(id Id, reason string) MergeResult
func NewMergeNewStatus ¶ added in v0.8.0
func NewMergeNewStatus(id Id, entity Interface) MergeResult
func NewMergeNothingStatus ¶ added in v0.8.0
func NewMergeNothingStatus(id Id) MergeResult
func NewMergeUpdatedStatus ¶ added in v0.8.0
func NewMergeUpdatedStatus(id Id, entity Interface) MergeResult
func (MergeResult) String ¶
func (mr MergeResult) String() string
type MergeStatus ¶
type MergeStatus int
MergeStatus represent the result of a merge operation of an entity
const ( MergeStatusNew MergeStatus // a new Entity was created locally MergeStatusInvalid // the remote data is invalid MergeStatusUpdated // a local Entity has been updated MergeStatusNothing // no changes were made to a local Entity (already up to date) MergeStatusError // a terminal error happened )
type Resolver ¶ added in v0.8.0
Resolver is an interface to find an Entity from its Id
func MakeResolver ¶ added in v0.8.0
MakeResolver create a resolver able to return the given entities.
type ResolverFunc ¶ added in v0.8.0
ResolverFunc is a helper to morph a function resolver into a Resolver
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package dag contains the base common code to define an entity stored in a chain of git objects, supporting actions like Push, Pull and Merge.
|
Package dag contains the base common code to define an entity stored in a chain of git objects, supporting actions like Push, Pull and Merge. |