From 24a76b23cef6c668b768937a997943b082be0db5 Mon Sep 17 00:00:00 2001 From: Jay Date: Mon, 4 May 2026 13:53:34 -0400 Subject: [PATCH] update to use roots event constructor and new created at type. --- filters/filters_test.go | 46 +++++++++++++++++++---------------------- subgraph.go | 2 +- subgraph_test.go | 12 +++++------ 3 files changed, 28 insertions(+), 32 deletions(-) diff --git a/filters/filters_test.go b/filters/filters_test.go index 1446b7c..661a68c 100644 --- a/filters/filters_test.go +++ b/filters/filters_test.go @@ -9,9 +9,7 @@ import ( // Helpers -func intPtr(i int) *int { - return &i -} +func intPtr(i int) *int { ptr := i; return &ptr } func expectEqualHeartwoodFilters(t *testing.T, got, want HeartwoodFilter) { t.Helper() @@ -61,11 +59,11 @@ func TestMarshalJSON(t *testing.T) { { name: "root fields only", filter: HeartwoodFilter{ - Root: roots.Filter{ - IDs: []string{"abc"}, - Kinds: []int{1}, - Since: intPtr(1000), - }, + Root: roots.NewFilter( + roots.WithIDs([]string{"abc"}), + roots.WithKinds([]int{1}), + roots.WithSince(1000), + ), }, expected: `{"ids":["abc"],"kinds":[1],"since":1000}`, }, @@ -88,9 +86,9 @@ func TestMarshalJSON(t *testing.T) { { name: "root and graph present", filter: HeartwoodFilter{ - Root: roots.Filter{ - IDs: []string{"abc"}, - }, + Root: roots.NewFilter( + roots.WithIDs([]string{"abc"}), + ), Graph: []GraphFilter{ {Kinds: []json.RawMessage{json.RawMessage(`1`)}}, }, @@ -128,11 +126,11 @@ func TestUnmarshalJSON(t *testing.T) { name: "root fields only", input: `{"ids":["abc"],"kinds":[1],"since":1000}`, expected: HeartwoodFilter{ - Root: roots.Filter{ - IDs: []string{"abc"}, - Kinds: []int{1}, - Since: intPtr(1000), - }, + Root: roots.NewFilter( + roots.WithIDs([]string{"abc"}), + roots.WithKinds([]int{1}), + roots.WithSince(1000), + ), }, }, { @@ -155,9 +153,9 @@ func TestUnmarshalJSON(t *testing.T) { name: "root and graph present", input: `{"ids":["abc"],"graph":[{"kinds":[1]}]}`, expected: HeartwoodFilter{ - Root: roots.Filter{ - IDs: []string{"abc"}, - }, + Root: roots.NewFilter( + roots.WithIDs([]string{"abc"}), + ), Graph: []GraphFilter{ {Kinds: []json.RawMessage{json.RawMessage(`1`)}}, }, @@ -167,12 +165,10 @@ func TestUnmarshalJSON(t *testing.T) { name: "graph is removed from root extensions", input: `{"ids":["abc"],"graph":[{"kinds":[1]}],"search":"bitcoin"}`, expected: HeartwoodFilter{ - Root: roots.Filter{ - IDs: []string{"abc"}, - Extensions: map[string]json.RawMessage{ - "search": json.RawMessage(`"bitcoin"`), - }, - }, + Root: roots.NewFilter( + roots.WithIDs([]string{"abc"}), + roots.WithExtension("search", json.RawMessage(`"bitcoin"`)), + ), Graph: []GraphFilter{ {Kinds: []json.RawMessage{json.RawMessage(`1`)}}, }, diff --git a/subgraph.go b/subgraph.go index 9d00bae..247aa24 100644 --- a/subgraph.go +++ b/subgraph.go @@ -91,7 +91,7 @@ func EventToSubgraph(e roots.Event, p ExpanderPipeline) *EventSubgraph { // Core pipeline functions -func newEventNode(eventID string, createdAt int, kind int, content string) *Node { +func newEventNode(eventID string, createdAt int64, kind int, content string) *Node { eventNode := NewEventNode(eventID) eventNode.Props["created_at"] = createdAt eventNode.Props["kind"] = kind diff --git a/subgraph_test.go b/subgraph_test.go index 8c12637..fcfd463 100644 --- a/subgraph_test.go +++ b/subgraph_test.go @@ -15,13 +15,13 @@ var ids = map[string]string{ "d": "dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd", } -var static = roots.Event{ - CreatedAt: 1000, - Kind: 1, - Content: "hello", -} +var static = roots.NewEvent( + roots.WithCreatedAt(1000), + roots.WithKind(1), + roots.WithContent("hello"), +) -func newFullEventNode(id string, createdAt, kind int, content string) *Node { +func newFullEventNode(id string, createdAt int64, kind int, content string) *Node { n := NewEventNode(id) n.Props["created_at"] = createdAt n.Props["kind"] = kind