aboutsummaryrefslogtreecommitdiffstats
path: root/entity/dag/example_test.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2022-08-18 16:03:48 +0200
committerGitHub <noreply@github.com>2022-08-18 16:03:48 +0200
commit6664a251f1893e6ddc183aa6061d6f0fd4f40a57 (patch)
treee42bcfc39ccf9284f645dde7ae5990c6d4995ade /entity/dag/example_test.go
parentec24de3f0d19ff1a56d0b12d389ec1535be43ea2 (diff)
parent45f5f852b71a63c142bca8b05efe53eebf142594 (diff)
downloadgit-bug-6664a251f1893e6ddc183aa6061d6f0fd4f40a57.tar.gz
Merge pull request #844 from MichaelMure/resolvers
WIP resolvers
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