Phase 1: EventToSubgraph and Expander accept ValidatedEvent
This commit is contained in:
+11
-11
@@ -69,14 +69,14 @@ func IsValidTag(t roots.Tag) bool {
|
|||||||
|
|
||||||
// Event to subgraph pipeline
|
// Event to subgraph pipeline
|
||||||
|
|
||||||
func EventToSubgraph(e roots.Event, p ExpanderPipeline) *EventSubgraph {
|
func EventToSubgraph(e roots.ValidatedEvent, p ExpanderPipeline) *EventSubgraph {
|
||||||
s := NewEventSubgraph()
|
s := NewEventSubgraph()
|
||||||
|
|
||||||
// Create core entities
|
// Create core entities
|
||||||
eventNode := newEventNode(e.ID, e.CreatedAt, e.Kind, e.Content)
|
eventNode := newEventNode(e.ID(), e.CreatedAt(), e.Kind(), e.Content())
|
||||||
userNode := newUserNode(e.PubKey)
|
userNode := newUserNode(e.PubKey())
|
||||||
signedRel := newSignedRel(userNode, eventNode)
|
signedRel := newSignedRel(userNode, eventNode)
|
||||||
tagNodes := newTagNodes(e.Tags)
|
tagNodes := newTagNodes(e.Tags())
|
||||||
tagRels := newTagRels(eventNode, tagNodes)
|
tagRels := newTagRels(eventNode, tagNodes)
|
||||||
|
|
||||||
// Populate subgraph
|
// Populate subgraph
|
||||||
@@ -137,7 +137,7 @@ func newTagRels(event *Node, tags []*Node) []*Relationship {
|
|||||||
|
|
||||||
// Expander Pipeline
|
// Expander Pipeline
|
||||||
|
|
||||||
type Expander func(e roots.Event, s *EventSubgraph)
|
type Expander func(e roots.ValidatedEvent, s *EventSubgraph)
|
||||||
type ExpanderPipeline []Expander
|
type ExpanderPipeline []Expander
|
||||||
|
|
||||||
func NewExpanderPipeline(expanders ...Expander) ExpanderPipeline {
|
func NewExpanderPipeline(expanders ...Expander) ExpanderPipeline {
|
||||||
@@ -152,7 +152,7 @@ func DefaultExpanders() []Expander {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExpandTaggedEvents(e roots.Event, s *EventSubgraph) {
|
func ExpandTaggedEvents(e roots.ValidatedEvent, s *EventSubgraph) {
|
||||||
for _, tag := range s.NodesByLabel("Tag") {
|
for _, tag := range s.NodesByLabel("Tag") {
|
||||||
if tag.Props["name"] != "e" {
|
if tag.Props["name"] != "e" {
|
||||||
continue
|
continue
|
||||||
@@ -170,7 +170,7 @@ func ExpandTaggedEvents(e roots.Event, s *EventSubgraph) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExpandTaggedUsers(e roots.Event, s *EventSubgraph) {
|
func ExpandTaggedUsers(e roots.ValidatedEvent, s *EventSubgraph) {
|
||||||
for _, tag := range s.NodesByLabel("Tag") {
|
for _, tag := range s.NodesByLabel("Tag") {
|
||||||
if tag.Props["name"] != "p" {
|
if tag.Props["name"] != "p" {
|
||||||
continue
|
continue
|
||||||
@@ -188,8 +188,8 @@ func ExpandTaggedUsers(e roots.Event, s *EventSubgraph) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExpandReplaceableEvents(e roots.Event, s *EventSubgraph) {
|
func ExpandReplaceableEvents(e roots.ValidatedEvent, s *EventSubgraph) {
|
||||||
if e.Kind != 0 && e.Kind != 3 && !(e.Kind >= 10000 && e.Kind < 20000) {
|
if e.Kind() != 0 && e.Kind() != 3 && !(e.Kind() >= 10000 && e.Kind() < 20000) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,7 +200,7 @@ func ExpandReplaceableEvents(e roots.Event, s *EventSubgraph) {
|
|||||||
|
|
||||||
var authorNode *Node
|
var authorNode *Node
|
||||||
for _, n := range s.NodesByLabel("User") {
|
for _, n := range s.NodesByLabel("User") {
|
||||||
if n.Props["pubkey"] == e.PubKey {
|
if n.Props["pubkey"] == e.PubKey() {
|
||||||
authorNode = n
|
authorNode = n
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -209,7 +209,7 @@ func ExpandReplaceableEvents(e roots.Event, s *EventSubgraph) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
rk := NewReplacementKeyNode(e.PubKey, e.Kind)
|
rk := NewReplacementKeyNode(e.PubKey(), e.Kind())
|
||||||
s.AddNode(rk)
|
s.AddNode(rk)
|
||||||
s.AddRel(NewIsReplaceableRel(eventNode, rk, nil))
|
s.AddRel(NewIsReplaceableRel(eventNode, rk, nil))
|
||||||
s.AddRel(NewForUserRel(rk, authorNode, nil))
|
s.AddRel(NewForUserRel(rk, authorNode, nil))
|
||||||
|
|||||||
@@ -235,7 +235,9 @@ func convertEventsToSubgraphs(
|
|||||||
) {
|
) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
for traveller := range inChan {
|
for traveller := range inChan {
|
||||||
subgraph := EventToSubgraph(traveller.Event, expanders)
|
// temporary adapter — removed in Phase 5
|
||||||
|
validated, _ := roots.NewValidatedEvent(traveller.Event)
|
||||||
|
subgraph := EventToSubgraph(validated, expanders)
|
||||||
traveller.Subgraph = subgraph
|
traveller.Subgraph = subgraph
|
||||||
convertedChan <- traveller
|
convertedChan <- traveller
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user