Merge pull request #1313 from alixander/get-children-ids

d2oracle: GetChildrenIDs
This commit is contained in:
Alexander Wang 2023-05-09 16:18:18 -07:00 committed by GitHub
commit 0cd2f27d4f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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 {