Merge pull request #1313 from alixander/get-children-ids
d2oracle: GetChildrenIDs
This commit is contained in:
commit
0cd2f27d4f
1 changed files with 17 additions and 0 deletions
|
|
@ -7,6 +7,23 @@ import (
|
||||||
"oss.terrastruct.com/d2/d2parser"
|
"oss.terrastruct.com/d2/d2parser"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func GetChildrenIDs(g *d2graph.Graph, absID string) (ids []string, _ error) {
|
||||||
|
mk, err := d2parser.ParseMapKey(absID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
obj, ok := g.Root.HasChild(d2graph.Key(mk.Key))
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("%v not found", absID)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, ch := range obj.ChildrenArray {
|
||||||
|
ids = append(ids, ch.AbsID())
|
||||||
|
}
|
||||||
|
|
||||||
|
return ids, nil
|
||||||
|
}
|
||||||
|
|
||||||
func GetParentID(g *d2graph.Graph, absID string) (string, error) {
|
func GetParentID(g *d2graph.Graph, absID string) (string, error) {
|
||||||
mk, err := d2parser.ParseMapKey(absID)
|
mk, err := d2parser.ParseMapKey(absID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue