aboutsummaryrefslogtreecommitdiffstats
path: root/entity/dag/example_test.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2022-08-13 12:08:48 +0200
committerMichael Muré <batolettre@gmail.com>2022-08-18 15:55:48 +0200
commit45f5f852b71a63c142bca8b05efe53eebf142594 (patch)
treecb92d9f598b13dda69fbbc652a21d0ad8dc314c2 /entity/dag/example_test.go
parentcd52872475f1b39f3fb6546606c1e78afb6c08e3 (diff)
downloadgit-bug-45f5f852b71a63c142bca8b05efe53eebf142594.tar.gz
core: generalized resolvers to resolve any entity time when unmarshalling an operation
Diffstat (limited to 'entity/dag/example_test.go')
-rw-r--r--entity/dag/example_test.go18
1 files changed, 13 insertions, 5 deletions
diff --git a/entity/dag/example_test.go b/entity/dag/example_test.go
index 94850bd9..39d77f8d 100644
--- a/entity/dag/example_test.go
+++ b/entity/dag/example_test.go
@@ -214,7 +214,7 @@ var def = dag.Definition{
// operationUnmarshaller is a function doing the de-serialization of the JSON data into our own
// concrete Operations. If needed, we can use the resolver to connect to other entities.
-func operationUnmarshaller(raw json.RawMessage, resolver identity.Resolver) (dag.Operation, error) {
+func operationUnmarshaller(raw json.RawMessage, resolvers entity.Resolvers) (dag.Operation, error) {
var t struct {
OperationType dag.OperationType `json:"type"`
}
@@ -245,7 +245,7 @@ func operationUnmarshaller(raw json.RawMessage, resolver identity.Resolver) (dag
case *AddAdministrator:
// We need to resolve identities
for i, stub := range op.ToAdd {
- iden, err := resolver.ResolveIdentity(stub.Id())
+ iden, err := entity.Resolve[identity.Interface](resolvers, stub.Id())
if err != nil {
return nil, err
}
@@ -254,7 +254,7 @@ func operationUnmarshaller(raw json.RawMessage, resolver identity.Resolver) (dag
case *RemoveAdministrator:
// We need to resolve identities
for i, stub := range op.ToRemove {
- iden, err := resolver.ResolveIdentity(stub.Id())
+ iden, err := entity.Resolve[identity.Interface](resolvers, stub.Id())
if err != nil {
return nil, err
}
@@ -282,13 +282,21 @@ func (pc ProjectConfig) Compile() *Snapshot {
// Read is a helper to load a ProjectConfig from a Repository
func Read(repo repository.ClockedRepo, id entity.Id) (*ProjectConfig, error) {
- e, err := dag.Read(def, repo, identity.NewSimpleResolver(repo), id)
+ e, err := dag.Read(def, repo, simpleResolvers(repo), id)
if err != nil {
return nil, err
}
return &ProjectConfig{Entity: e}, nil
}
+func simpleResolvers(repo repository.ClockedRepo) entity.Resolvers {
+ // resolvers can look a bit complex or out of place here, but it's an important concept
+ // to allow caching and flexibility when constructing the final app.
+ return entity.Resolvers{
+ &identity.Identity{}: identity.NewSimpleResolver(repo),
+ }
+}
+
func Example_entity() {
const gitBugNamespace = "git-bug"
// Note: this example ignore errors for readability
@@ -323,7 +331,7 @@ func Example_entity() {
_ = confRene.Commit(repoRene)
// Isaac pull and read the config
- _ = dag.Pull(def, repoIsaac, identity.NewSimpleResolver(repoIsaac), "origin", isaac)
+ _ = dag.Pull(def, repoIsaac, simpleResolvers(repoIsaac), "origin", isaac)
confIsaac, _ := Read(repoIsaac, confRene.Id())
// Compile gives the current state of the config