Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Rename StartTS option methods #185

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,22 @@ func Typecheck(enabled bool) QueryOptFn {
// StreamOptFn function to set options on the [Client.Stream]
type StreamOptFn func(req *streamRequest)

// StartTime set the streams starting timestamp.
// StreamStartTime set the streams starting timestamp.
//
// Useful when resuming a stream at a given point in time.
func StartTime(ts int64) StreamOptFn {
return func(req *streamRequest) { req.StartTS = ts }
func StreamStartTime(ts time.Time) StreamOptFn {
return func(req *streamRequest) {
req.StartTS = ts.UnixMicro()
}
}

// StreamStartTimeUnixMicros set the stream starting timestamp.
//
// Useful when resuming a stream at a given point in time.
func StreamStartTimeUnixMicros(ts int64) StreamOptFn {
return func(req *streamRequest) {
req.StartTS = ts
}
}

// EventCursor set the stream starting point based on a previously received
Expand Down Expand Up @@ -178,20 +189,22 @@ func EventFeedCursor(cursor string) FeedOptFn {
}

// EventFeedStartTime set the start time for the [fauna.EventFeed]
// cannot be used with [EventFeedCursor] -- expects unix micro timestamp
func EventFeedStartTime(ts int64) FeedOptFn {
return func(req *feedOptions) { req.StartTS = &ts }
}

// EventFeedStartTimeFromTime set the start time for the [fauna.EventFeed]
// from a time.Time -- cannot be used with [EventFeedCursor]
func EventFeedStartTimeFromTime(ts time.Time) FeedOptFn {
// cannot be used with [EventFeedCursor]
func EventFeedStartTime(ts time.Time) FeedOptFn {
return func(req *feedOptions) {
asMicro := ts.UnixMicro()
req.StartTS = &asMicro
}
}

// EventFeedStartTimeUnixMicros set the start time for the [fauna.EventFeed]
// cannot be used with [EventFeedCursor]
func EventFeedStartTimeUnixMicros(ts int64) FeedOptFn {
return func(req *feedOptions) {
req.StartTS = &ts
}
}

// EventFeedPageSize set the page size for the [fauna.EventFeed]
func EventFeedPageSize(ts int) FeedOptFn {
return func(req *feedOptions) { req.PageSize = &ts }
Expand Down
4 changes: 2 additions & 2 deletions event_feed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestEventFeed(t *testing.T) {
unmarshalErr := req.Unmarshal(&response)
require.NoError(t, unmarshalErr, "failed to unmarshal EventSource")

_, feedErr := client.Feed(response, fauna.EventFeedStartTime(time.Now().UnixMicro()), fauna.EventFeedCursor("cursor"))
_, feedErr := client.Feed(response, fauna.EventFeedStartTime(time.Now()), fauna.EventFeedCursor("cursor"))
require.ErrorContains(t, feedErr, "cannot use EventFeedStartTime and EventFeedCursor together")
})
})
Expand Down Expand Up @@ -119,7 +119,7 @@ func TestEventFeed(t *testing.T) {
eventSource = getEventSource(t, client)
require.NotNil(t, eventSource, "failed to get an EventSource")

feed, feedErr = client.Feed(eventSource, fauna.EventFeedStartTimeFromTime(time.Now().Add(-10*time.Minute)))
feed, feedErr = client.Feed(eventSource, fauna.EventFeedStartTime(time.Now().Add(-10*time.Minute)))
require.NoError(t, feedErr, "failed to init events feed")

eventsErr = feed.Next(&page)
Expand Down
2 changes: 1 addition & 1 deletion stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func TestStreaming(t *testing.T) {
bar, err := client.Query(createBarQ)
require.NoError(t, err)

events, err := client.Stream(stream, fauna.StartTime(foo.TxnTime))
events, err := client.Stream(stream, fauna.StreamStartTimeUnixMicros(foo.TxnTime))
require.NoError(t, err)
defer func() {
_ = events.Close()
Expand Down
Loading