Changeset 0.15.0 (#71)

This commit is contained in:
2026-02-26 21:19:55 +00:00
parent e2149e249d
commit 2d79ff593b
35 changed files with 3218 additions and 504 deletions

View File

@@ -0,0 +1,38 @@
package treepath
import "encoding/json"
// IsSummaryMessage checks if a PathMessage has summary metadata
// (metadata.type == "summary").
func IsSummaryMessage(m *PathMessage) bool {
if m.Metadata == nil {
return false
}
meta := ParseMetadata(m)
return meta["type"] == "summary"
}
// ParseMetadata unmarshals the JSONB metadata on a PathMessage.
// Returns an empty map on any error.
func ParseMetadata(m *PathMessage) map[string]interface{} {
if m.Metadata == nil {
return map[string]interface{}{}
}
var meta map[string]interface{}
if err := json.Unmarshal(*m.Metadata, &meta); err != nil {
return map[string]interface{}{}
}
return meta
}
// FindSummaryBoundary returns the index of the most recent summary node
// in a path, or -1 if no summary exists.
func FindSummaryBoundary(path []PathMessage) int {
idx := -1
for i := range path {
if IsSummaryMessage(&path[i]) {
idx = i
}
}
return idx
}