/
graph.go
119 lines (91 loc) · 2.87 KB
/
graph.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//go:generate go run gen/edges.go
//go:generate go run gen/nodemap.go
//go:generate go run gen/nodeslice.go
package graph
import (
"context"
"gopkg.in/yaml.v2"
"regexp"
)
func Print(i interface{}, exclude ...string) {
println(Sprint(i, exclude...))
}
func Sprint(i interface{}, exclude ...string) (string) {
b, err := yaml.Marshal(i)
if err != nil {
panic(err)
}
re := regexp.MustCompile("(?m)[\r\n]+^.*xxx_unrecognized.*$")
res := re.ReplaceAll(b, []byte{})
re = regexp.MustCompile("(?m)[\r\n]+^.*: null.*$")
res = re.ReplaceAll(res, []byte{})
re = regexp.MustCompile("(?m)[\r\n]+^.*: {}.*$")
res = re.ReplaceAll(res, []byte{})
for _, e := range exclude {
re = regexp.MustCompile("(?m)[\r\n]+^.*" + e + ".*$")
res = re.ReplaceAll(res, []byte{})
}
return string(res)
}
func GetTypeDependenciesFromTypeIds(rn *RootNode, tnm TypeNodeMap) (TypeNodeMap) {
ctx := context.Background()
seenTypes, _ := ctx.Value("seenTypes").(map[NodeId]bool)
if seenTypes == nil {
seenTypes = map[NodeId]bool{}
ctx = context.WithValue(ctx, "seenTypes", seenTypes)
}
ids0 := NodeIds{}
tnm.Each(func(tn *TypeNode) {
ids0 = append(ids0, tn.Edges.Types.Resolver.dependencies(ctx)...)
})
return rn.Types.ByIds(ids0...)
}
func GetEnumDependenciesFromTypeIds(rn *RootNode, tnm TypeNodeMap) (EnumNodeMap) {
ctx := context.Background()
seenTypes, _ := ctx.Value("seenTypes").(map[NodeId]bool)
if seenTypes == nil {
seenTypes = map[NodeId]bool{}
ctx = context.WithValue(ctx, "seenTypes", seenTypes)
}
seenEnums, _ := ctx.Value("seenEnums").(map[NodeId]bool)
if seenEnums == nil {
seenEnums = map[NodeId]bool{}
ctx = context.WithValue(ctx, "seenEnums", seenEnums)
}
ids0 := NodeIds{}
tnm.Each(func(tn *TypeNode) {
ids0 = append(ids0, tn.Edges.Enums.Resolver.dependencies(ctx)...)
})
return rn.Enums.ByIds(ids0...)
}
func GetTypeDependenciesFromEndpointIds(rn *RootNode, enm EndpointNodeMap) (TypeNodeMap) {
ctx := context.Background()
seenTypes, _ := ctx.Value("seenTypes").(map[NodeId]bool)
if seenTypes == nil {
seenTypes = map[NodeId]bool{}
ctx = context.WithValue(ctx, "seenTypes", seenTypes)
}
ids0 := NodeIds{}
enm.Each(func(en *EndpointNode) {
ids0 = append(ids0, en.Edges.Types.Resolver.dependencies(ctx)...)
})
return rn.Types.ByIds(ids0...)
}
func GetEnumDependenciesFromEndpointIds(rn *RootNode, enm EndpointNodeMap) (EnumNodeMap) {
ctx := context.Background()
seenTypes, _ := ctx.Value("seenTypes").(map[NodeId]bool)
if seenTypes == nil {
seenTypes = map[NodeId]bool{}
ctx = context.WithValue(ctx, "seenTypes", seenTypes)
}
seenEnums, _ := ctx.Value("seenEnums").(map[NodeId]bool)
if seenEnums == nil {
seenEnums = map[NodeId]bool{}
ctx = context.WithValue(ctx, "seenEnums", seenEnums)
}
ids0 := NodeIds{}
enm.Each(func(en *EndpointNode) {
ids0 = append(ids0, en.Edges.Enums.Resolver.dependencies(ctx)...)
})
return rn.Enums.ByIds(ids0...)
}