feat: eventMeta -> event.IsEvent

This commit is contained in:
Jon Lundy
2023-04-02 16:45:17 -06:00
parent 6ee995298b
commit 9168f5c7bc
16 changed files with 186 additions and 290 deletions

View File

@@ -45,13 +45,13 @@ func (*noop) IsResolver() {}
func (*noop) CreateSaltyUser(ctx context.Context, nick string, pubkey string) (*salty.SaltyUser, error) { func (*noop) CreateSaltyUser(ctx context.Context, nick string, pubkey string) (*salty.SaltyUser, error) {
panic("not implemented") panic("not implemented")
} }
func (*noop) Posts(ctx context.Context, streamID string, paging *gql.PageInput) (*gql.Connection, error) { func (*noop) Posts(ctx context.Context, name, tag string, paging *gql.PageInput) (*gql.Connection, error) {
panic("not implemented") panic("not implemented")
} }
func (*noop) SaltyUser(ctx context.Context, nick string) (*salty.SaltyUser, error) { func (*noop) SaltyUser(ctx context.Context, nick string) (*salty.SaltyUser, error) {
panic("not implemented") panic("not implemented")
} }
func (*noop) PostAdded(ctx context.Context, streamID string, after int64) (<-chan *msgbus.PostEvent, error) { func (*noop) PostAdded(ctx context.Context, name, tag string, after int64) (<-chan *msgbus.PostEvent, error) {
panic("not implemented") panic("not implemented")
} }
func (*noop) Events(ctx context.Context, streamID string, paging *gql.PageInput) (*gql.Connection, error) { func (*noop) Events(ctx context.Context, streamID string, paging *gql.PageInput) (*gql.Connection, error) {

View File

@@ -1,9 +1,9 @@
extend type Query { extend type Query {
posts(streamID: String! paging: PageInput): Connection! posts(name: String!, tag: String! = "", paging: PageInput): Connection!
} }
extend type Subscription { extend type Subscription {
"""after == 0 start from begining, after == -1 start from end""" """after == 0 start from begining, after == -1 start from end"""
postAdded(streamID: String! after: Int! = -1): PostEvent postAdded(name: String!, tag: String! = "", after: Int! = -1): PostEvent
} }
type PostEvent implements Edge @goModel(model: "go.sour.is/ev/app/msgbus.PostEvent") { type PostEvent implements Edge @goModel(model: "go.sour.is/ev/app/msgbus.PostEvent") {
id: ID! id: ID!

View File

@@ -3,8 +3,10 @@ package msgbus
import ( import (
"bytes" "bytes"
"context" "context"
"encoding/base64"
"encoding/json" "encoding/json"
"fmt" "fmt"
"hash/fnv"
"io" "io"
"net/http" "net/http"
"strconv" "strconv"
@@ -33,8 +35,8 @@ type service struct {
} }
type MsgbusResolver interface { type MsgbusResolver interface {
Posts(ctx context.Context, streamID string, paging *gql.PageInput) (*gql.Connection, error) Posts(ctx context.Context, name, tag string, paging *gql.PageInput) (*gql.Connection, error)
PostAdded(ctx context.Context, streamID string, after int64) (<-chan *PostEvent, error) PostAdded(ctx context.Context, name, tag string, after int64) (<-chan *PostEvent, error)
IsResolver() IsResolver()
} }
@@ -115,7 +117,7 @@ func (s *service) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
// Posts is the resolver for the events field. // Posts is the resolver for the events field.
func (s *service) Posts(ctx context.Context, streamID string, paging *gql.PageInput) (*gql.Connection, error) { func (s *service) Posts(ctx context.Context, name, tag string, paging *gql.PageInput) (*gql.Connection, error) {
ctx, span := lg.Span(ctx) ctx, span := lg.Span(ctx)
defer span.End() defer span.End()
@@ -124,6 +126,7 @@ func (s *service) Posts(ctx context.Context, streamID string, paging *gql.PageIn
start := time.Now() start := time.Now()
defer s.m_req_time.Record(ctx, time.Since(start).Milliseconds()) defer s.m_req_time.Record(ctx, time.Since(start).Milliseconds())
streamID := withTag("post-"+name, tag)
lis, err := s.es.Read(ctx, streamID, paging.GetIdx(0), paging.GetCount(30)) lis, err := s.es.Read(ctx, streamID, paging.GetIdx(0), paging.GetCount(30))
if err != nil { if err != nil {
span.RecordError(err) span.RecordError(err)
@@ -164,7 +167,7 @@ func (s *service) Posts(ctx context.Context, streamID string, paging *gql.PageIn
}, nil }, nil
} }
func (r *service) PostAdded(ctx context.Context, streamID string, after int64) (<-chan *PostEvent, error) { func (r *service) PostAdded(ctx context.Context, name, tag string, after int64) (<-chan *PostEvent, error) {
ctx, span := lg.Span(ctx) ctx, span := lg.Span(ctx)
defer span.End() defer span.End()
@@ -175,6 +178,8 @@ func (r *service) PostAdded(ctx context.Context, streamID string, after int64) (
return nil, fmt.Errorf("EventStore does not implement streaming") return nil, fmt.Errorf("EventStore does not implement streaming")
} }
streamID := withTag("post-"+name, tag)
sub, err := es.Subscribe(ctx, streamID, after) sub, err := es.Subscribe(ctx, streamID, after)
if err != nil { if err != nil {
span.RecordError(err) span.RecordError(err)
@@ -232,14 +237,15 @@ func (s *service) get(w http.ResponseWriter, r *http.Request) {
start := time.Now() start := time.Now()
defer s.m_req_time.Record(ctx, time.Since(start).Milliseconds()) defer s.m_req_time.Record(ctx, time.Since(start).Milliseconds())
name, _, _ := strings.Cut(r.URL.Path, "/") name, tag, _ := strings.Cut(r.URL.Path, "/")
if name == "" { if name == "" {
w.WriteHeader(http.StatusNotFound) w.WriteHeader(http.StatusNotFound)
return return
} }
streamID := withTag("post-"+name, tag)
var first event.Event = event.NilEvent var first event.Event = event.NilEvent
if lis, err := s.es.Read(ctx, "post-"+name, 0, 1); err == nil && len(lis) > 0 { if lis, err := s.es.Read(ctx, streamID, 0, 1); err == nil && len(lis) > 0 {
first = lis[0] first = lis[0]
} }
@@ -256,8 +262,8 @@ func (s *service) get(w http.ResponseWriter, r *http.Request) {
count = i count = i
} }
span.AddEvent(fmt.Sprint("GET topic=", name, " idx=", pos, " n=", count)) span.AddEvent(fmt.Sprint("GET topic=", streamID, " idx=", pos, " n=", count))
events, err := s.es.Read(ctx, "post-"+name, pos, count) events, err := s.es.Read(ctx, streamID, pos, count)
if err != nil { if err != nil {
span.RecordError(err) span.RecordError(err)
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
@@ -356,14 +362,16 @@ func (s *service) websocket(w http.ResponseWriter, r *http.Request) {
ctx, span := lg.Span(ctx) ctx, span := lg.Span(ctx)
defer span.End() defer span.End()
name, _, _ := strings.Cut(r.URL.Path, "/") name, tag, _ := strings.Cut(r.URL.Path, "/")
if name == "" { if name == "" {
w.WriteHeader(http.StatusNotFound) w.WriteHeader(http.StatusNotFound)
return return
} }
streamID := withTag("post-"+name, tag)
var first event.Event = event.NilEvent var first event.Event = event.NilEvent
if lis, err := s.es.Read(ctx, "post-"+name, 0, 1); err == nil && len(lis) > 0 { if lis, err := s.es.Read(ctx, streamID, 0, 1); err == nil && len(lis) > 0 {
first = lis[0] first = lis[0]
} }
@@ -374,7 +382,7 @@ func (s *service) websocket(w http.ResponseWriter, r *http.Request) {
pos = i - 1 pos = i - 1
} }
span.AddEvent(fmt.Sprint("WS topic=", name, " idx=", pos)) span.AddEvent(fmt.Sprint("WS topic=", streamID, " idx=", pos))
c, err := upgrader.Upgrade(w, r, nil) c, err := upgrader.Upgrade(w, r, nil)
if err != nil { if err != nil {
@@ -409,7 +417,7 @@ func (s *service) websocket(w http.ResponseWriter, r *http.Request) {
return return
} }
sub, err := es.Subscribe(ctx, "post-"+name, pos) sub, err := es.Subscribe(ctx, streamID, pos)
if err != nil { if err != nil {
span.RecordError(err) span.RecordError(err)
return return
@@ -457,21 +465,9 @@ type PostEvent struct {
payload []byte payload []byte
tags []string tags []string
eventMeta event.Meta event.IsEvent
} }
func (e *PostEvent) EventMeta() event.Meta {
if e == nil {
return event.Meta{}
}
return e.eventMeta
}
func (e *PostEvent) SetEventMeta(eventMeta event.Meta) {
if e == nil {
return
}
e.eventMeta = eventMeta
}
func (e *PostEvent) Values() any { func (e *PostEvent) Values() any {
if e == nil { if e == nil {
return nil return nil
@@ -503,25 +499,23 @@ func (e *PostEvent) UnmarshalBinary(b []byte) error {
func (e *PostEvent) MarshalJSON() ([]byte, error) { return e.MarshalBinary() } func (e *PostEvent) MarshalJSON() ([]byte, error) { return e.MarshalBinary() }
func (e *PostEvent) UnmarshalJSON(b []byte) error { return e.UnmarshalBinary(b) } func (e *PostEvent) UnmarshalJSON(b []byte) error { return e.UnmarshalBinary(b) }
func (e *PostEvent) ID() string { return e.eventMeta.GetEventID() } func (e *PostEvent) ID() string { return e.EventMeta().GetEventID() }
func (e *PostEvent) Tags() []string { return e.tags } func (e *PostEvent) Tags() []string { return e.tags }
func (e *PostEvent) Payload() string { return string(e.payload) } func (e *PostEvent) Payload() string { return string(e.payload) }
func (e *PostEvent) PayloadJSON(ctx context.Context) (m map[string]interface{}, err error) { func (e *PostEvent) PayloadJSON(ctx context.Context) (m map[string]interface{}, err error) {
err = json.Unmarshal([]byte(e.payload), &m) err = json.Unmarshal([]byte(e.payload), &m)
return return
} }
func (e *PostEvent) Meta() *event.Meta { return &e.eventMeta } func (e *PostEvent) Meta() event.Meta { return e.EventMeta() }
func (e *PostEvent) IsEdge() {} func (e *PostEvent) IsEdge() {}
func (e *PostEvent) String() string { func (e *PostEvent) String() string {
var b bytes.Buffer var b bytes.Buffer
// b.WriteString(e.eventMeta.StreamID) b.WriteString(strconv.FormatUint(e.EventMeta().Position, 10))
// b.WriteRune('@')
b.WriteString(strconv.FormatUint(e.eventMeta.Position, 10))
b.WriteRune('\t') b.WriteRune('\t')
b.WriteString(e.eventMeta.EventID.String()) b.WriteString(e.EventMeta().EventID.String())
b.WriteRune('\t') b.WriteRune('\t')
b.WriteString(string(e.payload)) b.WriteString(string(e.payload))
if len(e.tags) > 0 { if len(e.tags) > 0 {
@@ -536,7 +530,7 @@ func fields(s string) []string {
if s == "" { if s == "" {
return nil return nil
} }
return strings.Split(s, "/") return strings.Split(s, ";")
} }
func encodeJSON(w io.Writer, first event.Event, events ...event.Event) error { func encodeJSON(w io.Writer, first event.Event, events ...event.Event) error {
@@ -573,3 +567,32 @@ func encodeJSON(w io.Writer, first event.Event, events ...event.Event) error {
return json.NewEncoder(w).Encode(out) return json.NewEncoder(w).Encode(out)
} }
func Projector(e event.Event) []event.Event {
m := e.EventMeta()
streamID := m.StreamID
streamPos := m.Position
switch e := e.(type) {
case *PostEvent:
lis := make([]event.Event, len(e.tags))
for i := range lis {
tag := e.tags[i]
ne := event.NewPtr(streamID, streamPos)
event.SetStreamID(withTag(streamID, tag), ne)
lis[i] = ne
}
return lis
}
return nil
}
func withTag(id, tag string) string {
if tag == "" {
return id
}
h := fnv.New128a()
fmt.Fprint(h, tag)
return id + "-" + base64.RawURLEncoding.EncodeToString(h.Sum(nil))
}

View File

@@ -51,22 +51,11 @@ func (a *Info) OnUpsert() error {
type VersionChanged struct { type VersionChanged struct {
ScriptVersion string `json:"script_version"` ScriptVersion string `json:"script_version"`
eventMeta event.Meta event.IsEvent
} }
var _ event.Event = (*VersionChanged)(nil) var _ event.Event = (*VersionChanged)(nil)
func (e *VersionChanged) EventMeta() event.Meta {
if e == nil {
return event.Meta{}
}
return e.eventMeta
}
func (e *VersionChanged) SetEventMeta(m event.Meta) {
if e != nil {
e.eventMeta = m
}
}
func (e *VersionChanged) MarshalBinary() (text []byte, err error) { func (e *VersionChanged) MarshalBinary() (text []byte, err error) {
return json.Marshal(e) return json.Marshal(e)
} }

View File

@@ -33,7 +33,7 @@ func (a *Request) ApplyEvent(lis ...event.Event) {
for _, e := range lis { for _, e := range lis {
switch e := e.(type) { switch e := e.(type) {
case *RequestSubmitted: case *RequestSubmitted:
a.RequestID = e.eventMeta.EventID.String() a.RequestID = e.EventMeta().EventID.String()
a.RequestIP = e.RequestIP a.RequestIP = e.RequestIP
a.Hidden = e.Hidden a.Hidden = e.Hidden
a.Created = ulid.Time(e.EventMeta().EventID.Time()) a.Created = ulid.Time(e.EventMeta().EventID.Time())
@@ -120,7 +120,7 @@ func (lis ListResponse) Swap(i, j int) {
} }
type RequestSubmitted struct { type RequestSubmitted struct {
eventMeta event.Meta event.IsEvent
RequestIP string `json:"req_ip"` RequestIP string `json:"req_ip"`
Hidden bool `json:"hide,omitempty"` Hidden bool `json:"hide,omitempty"`
@@ -154,22 +154,11 @@ func (r *RequestSubmitted) Family() int {
} }
} }
func (r *RequestSubmitted) String() string { func (r *RequestSubmitted) String() string {
return fmt.Sprint(r.eventMeta.EventID, r.RequestIP, r.Hidden, r.CreatedString()) return fmt.Sprint(r.EventMeta().EventID, r.RequestIP, r.Hidden, r.CreatedString())
} }
var _ event.Event = (*RequestSubmitted)(nil) var _ event.Event = (*RequestSubmitted)(nil)
func (e *RequestSubmitted) EventMeta() event.Meta {
if e == nil {
return event.Meta{}
}
return e.eventMeta
}
func (e *RequestSubmitted) SetEventMeta(m event.Meta) {
if e != nil {
e.eventMeta = m
}
}
func (e *RequestSubmitted) MarshalBinary() (text []byte, err error) { func (e *RequestSubmitted) MarshalBinary() (text []byte, err error) {
return json.Marshal(e) return json.Marshal(e)
} }
@@ -204,7 +193,7 @@ func (e *RequestSubmitted) MarshalEnviron() ([]byte, error) {
} }
type ResultSubmitted struct { type ResultSubmitted struct {
eventMeta event.Meta event.IsEvent
RequestID string `json:"req_id"` RequestID string `json:"req_id"`
PeerID string `json:"peer_id"` PeerID string `json:"peer_id"`
@@ -219,22 +208,11 @@ type ResultSubmitted struct {
} }
func (r *ResultSubmitted) Created() time.Time { func (r *ResultSubmitted) Created() time.Time {
return r.eventMeta.Created() return r.EventMeta().Created()
} }
var _ event.Event = (*ResultSubmitted)(nil) var _ event.Event = (*ResultSubmitted)(nil)
func (e *ResultSubmitted) EventMeta() event.Meta {
if e == nil {
return event.Meta{}
}
return e.eventMeta
}
func (e *ResultSubmitted) SetEventMeta(m event.Meta) {
if e != nil {
e.eventMeta = m
}
}
func (e *ResultSubmitted) MarshalBinary() (text []byte, err error) { func (e *ResultSubmitted) MarshalBinary() (text []byte, err error) {
return json.Marshal(e) return json.Marshal(e)
} }
@@ -248,22 +226,11 @@ func (e *ResultSubmitted) String() string {
type RequestTruncated struct { type RequestTruncated struct {
RequestID string RequestID string
eventMeta event.Meta event.IsEvent
} }
var _ event.Event = (*RequestTruncated)(nil) var _ event.Event = (*RequestTruncated)(nil)
func (e *RequestTruncated) EventMeta() event.Meta {
if e == nil {
return event.Meta{}
}
return e.eventMeta
}
func (e *RequestTruncated) SetEventMeta(m event.Meta) {
if e != nil {
e.eventMeta = m
}
}
func (e *RequestTruncated) MarshalBinary() (text []byte, err error) { func (e *RequestTruncated) MarshalBinary() (text []byte, err error) {
return json.Marshal(e) return json.Marshal(e)
} }

View File

@@ -164,7 +164,7 @@ func (s *service) cleanRequests(ctx context.Context, now time.Time) error {
for _, event := range events { for _, event := range events {
switch e := event.(type) { switch e := event.(type) {
case *RequestSubmitted: case *RequestSubmitted:
if e.eventMeta.ActualPosition < last-maxResults { if e.EventMeta().ActualPosition < last-maxResults {
streamIDs = append(streamIDs, e.RequestID()) streamIDs = append(streamIDs, e.RequestID())
} }
} }

View File

@@ -60,22 +60,11 @@ type UserRegistered struct {
Name string Name string
Pubkey *keys.EdX25519PublicKey Pubkey *keys.EdX25519PublicKey
eventMeta event.Meta event.IsEvent
} }
var _ event.Event = (*UserRegistered)(nil) var _ event.Event = (*UserRegistered)(nil)
func (e *UserRegistered) EventMeta() event.Meta {
if e == nil {
return event.Meta{}
}
return e.eventMeta
}
func (e *UserRegistered) SetEventMeta(m event.Meta) {
if e != nil {
e.eventMeta = m
}
}
func (e *UserRegistered) MarshalBinary() (text []byte, err error) { func (e *UserRegistered) MarshalBinary() (text []byte, err error) {
var b bytes.Buffer var b bytes.Buffer
b.WriteString(e.Name) b.WriteString(e.Name)

View File

@@ -11,20 +11,9 @@ type SubjectSet struct {
Aliases []string `json:"aliases,omitempty"` Aliases []string `json:"aliases,omitempty"`
Properties map[string]*string `json:"properties,omitempty"` Properties map[string]*string `json:"properties,omitempty"`
eventMeta event.Meta event.IsEvent
} }
func (e *SubjectSet) EventMeta() event.Meta {
if e == nil {
return event.Meta{}
}
return e.eventMeta
}
func (e *SubjectSet) SetEventMeta(m event.Meta) {
if e != nil {
e.eventMeta = m
}
}
func (e *SubjectSet) MarshalBinary() (text []byte, err error) { func (e *SubjectSet) MarshalBinary() (text []byte, err error) {
return json.Marshal(e) return json.Marshal(e)
} }
@@ -37,20 +26,9 @@ var _ event.Event = (*SubjectSet)(nil)
type SubjectDeleted struct { type SubjectDeleted struct {
Subject string `json:"subject"` Subject string `json:"subject"`
eventMeta event.Meta event.IsEvent
} }
func (e *SubjectDeleted) EventMeta() event.Meta {
if e == nil {
return event.Meta{}
}
return e.eventMeta
}
func (e *SubjectDeleted) SetEventMeta(m event.Meta) {
if e != nil {
e.eventMeta = m
}
}
func (e *SubjectDeleted) MarshalBinary() (text []byte, err error) { func (e *SubjectDeleted) MarshalBinary() (text []byte, err error) {
return json.Marshal(e) return json.Marshal(e)
} }
@@ -67,20 +45,9 @@ type LinkSet struct {
Titles map[string]string `json:"titles,omitempty"` Titles map[string]string `json:"titles,omitempty"`
Properties map[string]*string `json:"properties,omitempty"` Properties map[string]*string `json:"properties,omitempty"`
eventMeta event.Meta event.IsEvent
} }
func (e *LinkSet) EventMeta() event.Meta {
if e == nil {
return event.Meta{}
}
return e.eventMeta
}
func (e *LinkSet) SetEventMeta(m event.Meta) {
if e != nil {
e.eventMeta = m
}
}
func (e *LinkSet) MarshalBinary() (text []byte, err error) { func (e *LinkSet) MarshalBinary() (text []byte, err error) {
return json.Marshal(e) return json.Marshal(e)
} }
@@ -93,20 +60,9 @@ var _ event.Event = (*LinkSet)(nil)
type LinkDeleted struct { type LinkDeleted struct {
Rel string `json:"rel"` Rel string `json:"rel"`
eventMeta event.Meta event.IsEvent
} }
func (e *LinkDeleted) EventMeta() event.Meta {
if e == nil {
return event.Meta{}
}
return e.eventMeta
}
func (e *LinkDeleted) SetEventMeta(m event.Meta) {
if e != nil {
e.eventMeta = m
}
}
func (e *LinkDeleted) MarshalBinary() (text []byte, err error) { func (e *LinkDeleted) MarshalBinary() (text []byte, err error) {
return json.Marshal(e) return json.Marshal(e)
} }

View File

@@ -8,6 +8,7 @@ import (
"go.sour.is/ev/app/msgbus" "go.sour.is/ev/app/msgbus"
"go.sour.is/ev/internal/lg" "go.sour.is/ev/internal/lg"
"go.sour.is/ev/pkg/service" "go.sour.is/ev/pkg/service"
"go.sour.is/ev/pkg/es/driver/projecter"
"go.sour.is/ev/pkg/slice" "go.sour.is/ev/pkg/slice"
) )
@@ -20,6 +21,7 @@ var _ = apps.Register(50, func(ctx context.Context, svc *service.Harness) error
if !ok { if !ok {
return fmt.Errorf("*es.EventStore not found in services") return fmt.Errorf("*es.EventStore not found in services")
} }
eventstore.Option(projecter.New(ctx, msgbus.Projector))
msgbus, err := msgbus.New(ctx, eventstore) msgbus, err := msgbus.New(ctx, eventstore)
if err != nil { if err != nil {

View File

@@ -48,21 +48,9 @@ func (a *Thing) OnSetValue(value string) error {
type ValueSet struct { type ValueSet struct {
Value string Value string
eventMeta event.Meta event.IsEvent
} }
func (e *ValueSet) EventMeta() event.Meta {
if e == nil {
return event.Meta{}
}
return e.eventMeta
}
func (e *ValueSet) SetEventMeta(eventMeta event.Meta) {
if e == nil {
return
}
e.eventMeta = eventMeta
}
func (e *ValueSet) MarshalBinary() ([]byte, error) { func (e *ValueSet) MarshalBinary() ([]byte, error) {
return json.Marshal(e) return json.Marshal(e)
} }

View File

@@ -16,13 +16,13 @@ import (
"github.com/99designs/gqlgen/graphql" "github.com/99designs/gqlgen/graphql"
"github.com/99designs/gqlgen/graphql/introspection" "github.com/99designs/gqlgen/graphql/introspection"
"github.com/99designs/gqlgen/plugin/federation/fedruntime" "github.com/99designs/gqlgen/plugin/federation/fedruntime"
gqlparser "github.com/vektah/gqlparser/v2"
"github.com/vektah/gqlparser/v2/ast"
"go.sour.is/ev/app/msgbus" "go.sour.is/ev/app/msgbus"
"go.sour.is/ev/app/salty" "go.sour.is/ev/app/salty"
"go.sour.is/ev/pkg/es" "go.sour.is/ev/pkg/es"
"go.sour.is/ev/pkg/es/event" "go.sour.is/ev/pkg/es/event"
"go.sour.is/ev/pkg/gql" "go.sour.is/ev/pkg/gql"
gqlparser "github.com/vektah/gqlparser/v2"
"github.com/vektah/gqlparser/v2/ast"
) )
// region ************************** generated!.gotpl ************************** // region ************************** generated!.gotpl **************************
@@ -99,7 +99,7 @@ type ComplexityRoot struct {
Query struct { Query struct {
Events func(childComplexity int, streamID string, paging *gql.PageInput) int Events func(childComplexity int, streamID string, paging *gql.PageInput) int
Posts func(childComplexity int, streamID string, paging *gql.PageInput) int Posts func(childComplexity int, name string, tag string, paging *gql.PageInput) int
SaltyUser func(childComplexity int, nick string) int SaltyUser func(childComplexity int, nick string) int
__resolve__service func(childComplexity int) int __resolve__service func(childComplexity int) int
} }
@@ -112,7 +112,7 @@ type ComplexityRoot struct {
Subscription struct { Subscription struct {
EventAdded func(childComplexity int, streamID string, after int64) int EventAdded func(childComplexity int, streamID string, after int64) int
PostAdded func(childComplexity int, streamID string, after int64) int PostAdded func(childComplexity int, name string, tag string, after int64) int
} }
_Service struct { _Service struct {
@@ -126,12 +126,12 @@ type MutationResolver interface {
} }
type QueryResolver interface { type QueryResolver interface {
Events(ctx context.Context, streamID string, paging *gql.PageInput) (*gql.Connection, error) Events(ctx context.Context, streamID string, paging *gql.PageInput) (*gql.Connection, error)
Posts(ctx context.Context, streamID string, paging *gql.PageInput) (*gql.Connection, error) Posts(ctx context.Context, name string, tag string, paging *gql.PageInput) (*gql.Connection, error)
SaltyUser(ctx context.Context, nick string) (*salty.SaltyUser, error) SaltyUser(ctx context.Context, nick string) (*salty.SaltyUser, error)
} }
type SubscriptionResolver interface { type SubscriptionResolver interface {
EventAdded(ctx context.Context, streamID string, after int64) (<-chan *es.GQLEvent, error) EventAdded(ctx context.Context, streamID string, after int64) (<-chan *es.GQLEvent, error)
PostAdded(ctx context.Context, streamID string, after int64) (<-chan *msgbus.PostEvent, error) PostAdded(ctx context.Context, name string, tag string, after int64) (<-chan *msgbus.PostEvent, error)
} }
type executableSchema struct { type executableSchema struct {
@@ -370,7 +370,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
return 0, false return 0, false
} }
return e.complexity.Query.Posts(childComplexity, args["streamID"].(string), args["paging"].(*gql.PageInput)), true return e.complexity.Query.Posts(childComplexity, args["name"].(string), args["tag"].(string), args["paging"].(*gql.PageInput)), true
case "Query.saltyUser": case "Query.saltyUser":
if e.complexity.Query.SaltyUser == nil { if e.complexity.Query.SaltyUser == nil {
@@ -434,7 +434,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
return 0, false return 0, false
} }
return e.complexity.Subscription.PostAdded(childComplexity, args["streamID"].(string), args["after"].(int64)), true return e.complexity.Subscription.PostAdded(childComplexity, args["name"].(string), args["tag"].(string), args["after"].(int64)), true
case "_Service.sdl": case "_Service.sdl":
if e.complexity._Service.SDL == nil { if e.complexity._Service.SDL == nil {
@@ -609,11 +609,11 @@ directive @goTag(
# set(namespace: String! key: String! value: String): Bool! # set(namespace: String! key: String! value: String): Bool!
# }`, BuiltIn: false}, # }`, BuiltIn: false},
{Name: "../../../app/msgbus/msgbus.graphqls", Input: `extend type Query { {Name: "../../../app/msgbus/msgbus.graphqls", Input: `extend type Query {
posts(streamID: String! paging: PageInput): Connection! posts(name: String!, tag: String! = "", paging: PageInput): Connection!
} }
extend type Subscription { extend type Subscription {
"""after == 0 start from begining, after == -1 start from end""" """after == 0 start from begining, after == -1 start from end"""
postAdded(streamID: String! after: Int! = -1): PostEvent postAdded(name: String!, tag: String! = "", after: Int! = -1): PostEvent
} }
type PostEvent implements Edge @goModel(model: "go.sour.is/ev/app/msgbus.PostEvent") { type PostEvent implements Edge @goModel(model: "go.sour.is/ev/app/msgbus.PostEvent") {
id: ID! id: ID!
@@ -742,7 +742,7 @@ func (ec *executionContext) field_Query_events_args(ctx context.Context, rawArgs
var arg1 *gql.PageInput var arg1 *gql.PageInput
if tmp, ok := rawArgs["paging"]; ok { if tmp, ok := rawArgs["paging"]; ok {
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("paging")) ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("paging"))
arg1, err = ec.unmarshalOPageInput2ᚖgithubᚗcomᚋsourisᚋevᚋpkgᚋgqlᚐPageInput(ctx, tmp) arg1, err = ec.unmarshalOPageInput2ᚖgoᚗsourisᚋevᚋpkgᚋgqlᚐPageInput(ctx, tmp)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -755,23 +755,32 @@ func (ec *executionContext) field_Query_posts_args(ctx context.Context, rawArgs
var err error var err error
args := map[string]interface{}{} args := map[string]interface{}{}
var arg0 string var arg0 string
if tmp, ok := rawArgs["streamID"]; ok { if tmp, ok := rawArgs["name"]; ok {
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("streamID")) ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("name"))
arg0, err = ec.unmarshalNString2string(ctx, tmp) arg0, err = ec.unmarshalNString2string(ctx, tmp)
if err != nil { if err != nil {
return nil, err return nil, err
} }
} }
args["streamID"] = arg0 args["name"] = arg0
var arg1 *gql.PageInput var arg1 string
if tmp, ok := rawArgs["paging"]; ok { if tmp, ok := rawArgs["tag"]; ok {
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("paging")) ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("tag"))
arg1, err = ec.unmarshalOPageInput2ᚖgithubᚗcomᚋsourᚑisᚋevᚋpkgᚋgqlᚐPageInput(ctx, tmp) arg1, err = ec.unmarshalNString2string(ctx, tmp)
if err != nil { if err != nil {
return nil, err return nil, err
} }
} }
args["paging"] = arg1 args["tag"] = arg1
var arg2 *gql.PageInput
if tmp, ok := rawArgs["paging"]; ok {
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("paging"))
arg2, err = ec.unmarshalOPageInput2ᚖgoᚗsourᚗisᚋevᚋpkgᚋgqlᚐPageInput(ctx, tmp)
if err != nil {
return nil, err
}
}
args["paging"] = arg2
return args, nil return args, nil
} }
@@ -818,23 +827,32 @@ func (ec *executionContext) field_Subscription_postAdded_args(ctx context.Contex
var err error var err error
args := map[string]interface{}{} args := map[string]interface{}{}
var arg0 string var arg0 string
if tmp, ok := rawArgs["streamID"]; ok { if tmp, ok := rawArgs["name"]; ok {
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("streamID")) ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("name"))
arg0, err = ec.unmarshalNString2string(ctx, tmp) arg0, err = ec.unmarshalNString2string(ctx, tmp)
if err != nil { if err != nil {
return nil, err return nil, err
} }
} }
args["streamID"] = arg0 args["name"] = arg0
var arg1 int64 var arg1 string
if tmp, ok := rawArgs["after"]; ok { if tmp, ok := rawArgs["tag"]; ok {
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("after")) ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("tag"))
arg1, err = ec.unmarshalNInt2int64(ctx, tmp) arg1, err = ec.unmarshalNString2string(ctx, tmp)
if err != nil { if err != nil {
return nil, err return nil, err
} }
} }
args["after"] = arg1 args["tag"] = arg1
var arg2 int64
if tmp, ok := rawArgs["after"]; ok {
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("after"))
arg2, err = ec.unmarshalNInt2int64(ctx, tmp)
if err != nil {
return nil, err
}
}
args["after"] = arg2
return args, nil return args, nil
} }
@@ -904,7 +922,7 @@ func (ec *executionContext) _Connection_paging(ctx context.Context, field graphq
} }
res := resTmp.(*gql.PageInfo) res := resTmp.(*gql.PageInfo)
fc.Result = res fc.Result = res
return ec.marshalNPageInfo2ᚖgithubᚗcomᚋsourisᚋevᚋpkgᚋgqlᚐPageInfo(ctx, field.Selections, res) return ec.marshalNPageInfo2ᚖgoᚗsourisᚋevᚋpkgᚋgqlᚐPageInfo(ctx, field.Selections, res)
} }
func (ec *executionContext) fieldContext_Connection_paging(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { func (ec *executionContext) fieldContext_Connection_paging(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
@@ -958,7 +976,7 @@ func (ec *executionContext) _Connection_edges(ctx context.Context, field graphql
} }
res := resTmp.([]gql.Edge) res := resTmp.([]gql.Edge)
fc.Result = res fc.Result = res
return ec.marshalNEdge2ᚕgithubᚗcomᚋsourisᚋevᚋpkgᚋgqlᚐEdgeᚄ(ctx, field.Selections, res) return ec.marshalNEdge2ᚕgoᚗsourisᚋevᚋpkgᚋgqlᚐEdgeᚄ(ctx, field.Selections, res)
} }
func (ec *executionContext) fieldContext_Connection_edges(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { func (ec *executionContext) fieldContext_Connection_edges(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
@@ -1354,7 +1372,7 @@ func (ec *executionContext) _Event_meta(ctx context.Context, field graphql.Colle
} }
res := resTmp.(*event.Meta) res := resTmp.(*event.Meta)
fc.Result = res fc.Result = res
return ec.marshalNMeta2ᚖgithubᚗcomᚋsourisᚋevᚋpkgᚋesᚋeventᚐMeta(ctx, field.Selections, res) return ec.marshalNMeta2ᚖgoᚗsourisᚋevᚋpkgᚋesᚋeventᚐMeta(ctx, field.Selections, res)
} }
func (ec *executionContext) fieldContext_Event_meta(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { func (ec *executionContext) fieldContext_Event_meta(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
@@ -1405,7 +1423,7 @@ func (ec *executionContext) _Event_linked(ctx context.Context, field graphql.Col
} }
res := resTmp.(*es.GQLEvent) res := resTmp.(*es.GQLEvent)
fc.Result = res fc.Result = res
return ec.marshalOEvent2ᚖgithubᚗcomᚋsourisᚋevᚋpkgᚋesᚐGQLEvent(ctx, field.Selections, res) return ec.marshalOEvent2ᚖgoᚗsourisᚋevᚋpkgᚋesᚐGQLEvent(ctx, field.Selections, res)
} }
func (ec *executionContext) fieldContext_Event_linked(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { func (ec *executionContext) fieldContext_Event_linked(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
@@ -1699,7 +1717,7 @@ func (ec *executionContext) _Mutation_createSaltyUser(ctx context.Context, field
} }
res := resTmp.(*salty.SaltyUser) res := resTmp.(*salty.SaltyUser)
fc.Result = res fc.Result = res
return ec.marshalOSaltyUser2ᚖgithubᚗcomᚋsourisᚋevᚋappᚋsaltyᚐSaltyUser(ctx, field.Selections, res) return ec.marshalOSaltyUser2ᚖgoᚗsourisᚋevᚋappᚋsaltyᚐSaltyUser(ctx, field.Selections, res)
} }
func (ec *executionContext) fieldContext_Mutation_createSaltyUser(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { func (ec *executionContext) fieldContext_Mutation_createSaltyUser(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
@@ -2112,9 +2130,9 @@ func (ec *executionContext) _PostEvent_meta(ctx context.Context, field graphql.C
} }
return graphql.Null return graphql.Null
} }
res := resTmp.(*event.Meta) res := resTmp.(event.Meta)
fc.Result = res fc.Result = res
return ec.marshalNMeta2ᚖgithubᚗcomᚋsourisᚋevᚋpkgᚋesᚋeventᚐMeta(ctx, field.Selections, res) return ec.marshalNMeta2goᚗsourisᚋevᚋpkgᚋesᚋeventᚐMeta(ctx, field.Selections, res)
} }
func (ec *executionContext) fieldContext_PostEvent_meta(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { func (ec *executionContext) fieldContext_PostEvent_meta(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
@@ -2168,7 +2186,7 @@ func (ec *executionContext) _Query_events(ctx context.Context, field graphql.Col
} }
res := resTmp.(*gql.Connection) res := resTmp.(*gql.Connection)
fc.Result = res fc.Result = res
return ec.marshalNConnection2ᚖgithubᚗcomᚋsourisᚋevᚋpkgᚋgqlᚐConnection(ctx, field.Selections, res) return ec.marshalNConnection2ᚖgoᚗsourisᚋevᚋpkgᚋgqlᚐConnection(ctx, field.Selections, res)
} }
func (ec *executionContext) fieldContext_Query_events(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { func (ec *executionContext) fieldContext_Query_events(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
@@ -2215,7 +2233,7 @@ func (ec *executionContext) _Query_posts(ctx context.Context, field graphql.Coll
}() }()
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
ctx = rctx // use context from middleware stack in children ctx = rctx // use context from middleware stack in children
return ec.resolvers.Query().Posts(rctx, fc.Args["streamID"].(string), fc.Args["paging"].(*gql.PageInput)) return ec.resolvers.Query().Posts(rctx, fc.Args["name"].(string), fc.Args["tag"].(string), fc.Args["paging"].(*gql.PageInput))
}) })
if err != nil { if err != nil {
ec.Error(ctx, err) ec.Error(ctx, err)
@@ -2229,7 +2247,7 @@ func (ec *executionContext) _Query_posts(ctx context.Context, field graphql.Coll
} }
res := resTmp.(*gql.Connection) res := resTmp.(*gql.Connection)
fc.Result = res fc.Result = res
return ec.marshalNConnection2ᚖgithubᚗcomᚋsourisᚋevᚋpkgᚋgqlᚐConnection(ctx, field.Selections, res) return ec.marshalNConnection2ᚖgoᚗsourisᚋevᚋpkgᚋgqlᚐConnection(ctx, field.Selections, res)
} }
func (ec *executionContext) fieldContext_Query_posts(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { func (ec *executionContext) fieldContext_Query_posts(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
@@ -2287,7 +2305,7 @@ func (ec *executionContext) _Query_saltyUser(ctx context.Context, field graphql.
} }
res := resTmp.(*salty.SaltyUser) res := resTmp.(*salty.SaltyUser)
fc.Result = res fc.Result = res
return ec.marshalOSaltyUser2ᚖgithubᚗcomᚋsourisᚋevᚋappᚋsaltyᚐSaltyUser(ctx, field.Selections, res) return ec.marshalOSaltyUser2ᚖgoᚗsourisᚋevᚋappᚋsaltyᚐSaltyUser(ctx, field.Selections, res)
} }
func (ec *executionContext) fieldContext_Query_saltyUser(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { func (ec *executionContext) fieldContext_Query_saltyUser(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
@@ -2664,7 +2682,7 @@ func (ec *executionContext) _Subscription_eventAdded(ctx context.Context, field
w.Write([]byte{'{'}) w.Write([]byte{'{'})
graphql.MarshalString(field.Alias).MarshalGQL(w) graphql.MarshalString(field.Alias).MarshalGQL(w)
w.Write([]byte{':'}) w.Write([]byte{':'})
ec.marshalOEvent2ᚖgithubᚗcomᚋsourisᚋevᚋpkgᚋesᚐGQLEvent(ctx, field.Selections, res).MarshalGQL(w) ec.marshalOEvent2ᚖgoᚗsourisᚋevᚋpkgᚋesᚐGQLEvent(ctx, field.Selections, res).MarshalGQL(w)
w.Write([]byte{'}'}) w.Write([]byte{'}'})
}) })
case <-ctx.Done(): case <-ctx.Done():
@@ -2733,7 +2751,7 @@ func (ec *executionContext) _Subscription_postAdded(ctx context.Context, field g
}() }()
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
ctx = rctx // use context from middleware stack in children ctx = rctx // use context from middleware stack in children
return ec.resolvers.Subscription().PostAdded(rctx, fc.Args["streamID"].(string), fc.Args["after"].(int64)) return ec.resolvers.Subscription().PostAdded(rctx, fc.Args["name"].(string), fc.Args["tag"].(string), fc.Args["after"].(int64))
}) })
if err != nil { if err != nil {
ec.Error(ctx, err) ec.Error(ctx, err)
@@ -2752,7 +2770,7 @@ func (ec *executionContext) _Subscription_postAdded(ctx context.Context, field g
w.Write([]byte{'{'}) w.Write([]byte{'{'})
graphql.MarshalString(field.Alias).MarshalGQL(w) graphql.MarshalString(field.Alias).MarshalGQL(w)
w.Write([]byte{':'}) w.Write([]byte{':'})
ec.marshalOPostEvent2ᚖgithubᚗcomᚋsourisᚋevᚋappᚋmsgbusᚐPostEvent(ctx, field.Selections, res).MarshalGQL(w) ec.marshalOPostEvent2ᚖgoᚗsourisᚋevᚋappᚋmsgbusᚐPostEvent(ctx, field.Selections, res).MarshalGQL(w)
w.Write([]byte{'}'}) w.Write([]byte{'}'})
}) })
case <-ctx.Done(): case <-ctx.Done():
@@ -5603,11 +5621,11 @@ func (ec *executionContext) marshalNBoolean2bool(ctx context.Context, sel ast.Se
return res return res
} }
func (ec *executionContext) marshalNConnection2githubᚗcomᚋsourisᚋevᚋpkgᚋgqlᚐConnection(ctx context.Context, sel ast.SelectionSet, v gql.Connection) graphql.Marshaler { func (ec *executionContext) marshalNConnection2goᚗsourisᚋevᚋpkgᚋgqlᚐConnection(ctx context.Context, sel ast.SelectionSet, v gql.Connection) graphql.Marshaler {
return ec._Connection(ctx, sel, &v) return ec._Connection(ctx, sel, &v)
} }
func (ec *executionContext) marshalNConnection2ᚖgithubᚗcomᚋsourisᚋevᚋpkgᚋgqlᚐConnection(ctx context.Context, sel ast.SelectionSet, v *gql.Connection) graphql.Marshaler { func (ec *executionContext) marshalNConnection2ᚖgoᚗsourisᚋevᚋpkgᚋgqlᚐConnection(ctx context.Context, sel ast.SelectionSet, v *gql.Connection) graphql.Marshaler {
if v == nil { if v == nil {
if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
ec.Errorf(ctx, "the requested element is null which the schema does not allow") ec.Errorf(ctx, "the requested element is null which the schema does not allow")
@@ -5617,7 +5635,7 @@ func (ec *executionContext) marshalNConnection2ᚖgithubᚗcomᚋsourᚑisᚋev
return ec._Connection(ctx, sel, v) return ec._Connection(ctx, sel, v)
} }
func (ec *executionContext) marshalNEdge2githubᚗcomᚋsourisᚋevᚋpkgᚋgqlᚐEdge(ctx context.Context, sel ast.SelectionSet, v gql.Edge) graphql.Marshaler { func (ec *executionContext) marshalNEdge2goᚗsourisᚋevᚋpkgᚋgqlᚐEdge(ctx context.Context, sel ast.SelectionSet, v gql.Edge) graphql.Marshaler {
if v == nil { if v == nil {
if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
ec.Errorf(ctx, "the requested element is null which the schema does not allow") ec.Errorf(ctx, "the requested element is null which the schema does not allow")
@@ -5627,7 +5645,7 @@ func (ec *executionContext) marshalNEdge2githubᚗcomᚋsourᚑisᚋevᚋpkgᚋg
return ec._Edge(ctx, sel, v) return ec._Edge(ctx, sel, v)
} }
func (ec *executionContext) marshalNEdge2ᚕgithubᚗcomᚋsourisᚋevᚋpkgᚋgqlᚐEdgeᚄ(ctx context.Context, sel ast.SelectionSet, v []gql.Edge) graphql.Marshaler { func (ec *executionContext) marshalNEdge2ᚕgoᚗsourisᚋevᚋpkgᚋgqlᚐEdgeᚄ(ctx context.Context, sel ast.SelectionSet, v []gql.Edge) graphql.Marshaler {
ret := make(graphql.Array, len(v)) ret := make(graphql.Array, len(v))
var wg sync.WaitGroup var wg sync.WaitGroup
isLen1 := len(v) == 1 isLen1 := len(v) == 1
@@ -5651,7 +5669,7 @@ func (ec *executionContext) marshalNEdge2ᚕgithubᚗcomᚋsourᚑisᚋevᚋpkg
if !isLen1 { if !isLen1 {
defer wg.Done() defer wg.Done()
} }
ret[i] = ec.marshalNEdge2githubᚗcomᚋsourisᚋevᚋpkgᚋgqlᚐEdge(ctx, sel, v[i]) ret[i] = ec.marshalNEdge2goᚗsourisᚋevᚋpkgᚋgqlᚐEdge(ctx, sel, v[i])
} }
if isLen1 { if isLen1 {
f(i) f(i)
@@ -5737,7 +5755,11 @@ func (ec *executionContext) marshalNMap2map(ctx context.Context, sel ast.Selecti
return res return res
} }
func (ec *executionContext) marshalNMeta2ᚖgithubᚗcomᚋsourisᚋevᚋpkgᚋesᚋeventᚐMeta(ctx context.Context, sel ast.SelectionSet, v *event.Meta) graphql.Marshaler { func (ec *executionContext) marshalNMeta2goᚗsourisᚋevᚋpkgᚋesᚋeventᚐMeta(ctx context.Context, sel ast.SelectionSet, v event.Meta) graphql.Marshaler {
return ec._Meta(ctx, sel, &v)
}
func (ec *executionContext) marshalNMeta2ᚖgoᚗsourᚗisᚋevᚋpkgᚋesᚋeventᚐMeta(ctx context.Context, sel ast.SelectionSet, v *event.Meta) graphql.Marshaler {
if v == nil { if v == nil {
if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
ec.Errorf(ctx, "the requested element is null which the schema does not allow") ec.Errorf(ctx, "the requested element is null which the schema does not allow")
@@ -5747,7 +5769,7 @@ func (ec *executionContext) marshalNMeta2ᚖgithubᚗcomᚋsourᚑisᚋevᚋpkg
return ec._Meta(ctx, sel, v) return ec._Meta(ctx, sel, v)
} }
func (ec *executionContext) marshalNPageInfo2ᚖgithubᚗcomᚋsourisᚋevᚋpkgᚋgqlᚐPageInfo(ctx context.Context, sel ast.SelectionSet, v *gql.PageInfo) graphql.Marshaler { func (ec *executionContext) marshalNPageInfo2ᚖgoᚗsourisᚋevᚋpkgᚋgqlᚐPageInfo(ctx context.Context, sel ast.SelectionSet, v *gql.PageInfo) graphql.Marshaler {
if v == nil { if v == nil {
if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
ec.Errorf(ctx, "the requested element is null which the schema does not allow") ec.Errorf(ctx, "the requested element is null which the schema does not allow")
@@ -6117,7 +6139,7 @@ func (ec *executionContext) marshalOBoolean2ᚖbool(ctx context.Context, sel ast
return res return res
} }
func (ec *executionContext) marshalOEvent2ᚖgithubᚗcomᚋsourisᚋevᚋpkgᚋesᚐGQLEvent(ctx context.Context, sel ast.SelectionSet, v *es.GQLEvent) graphql.Marshaler { func (ec *executionContext) marshalOEvent2ᚖgoᚗsourisᚋevᚋpkgᚋesᚐGQLEvent(ctx context.Context, sel ast.SelectionSet, v *es.GQLEvent) graphql.Marshaler {
if v == nil { if v == nil {
return graphql.Null return graphql.Null
} }
@@ -6140,7 +6162,7 @@ func (ec *executionContext) marshalOInt2ᚖint64(ctx context.Context, sel ast.Se
return res return res
} }
func (ec *executionContext) unmarshalOPageInput2ᚖgithubᚗcomᚋsourisᚋevᚋpkgᚋgqlᚐPageInput(ctx context.Context, v interface{}) (*gql.PageInput, error) { func (ec *executionContext) unmarshalOPageInput2ᚖgoᚗsourisᚋevᚋpkgᚋgqlᚐPageInput(ctx context.Context, v interface{}) (*gql.PageInput, error) {
if v == nil { if v == nil {
return nil, nil return nil, nil
} }
@@ -6148,14 +6170,14 @@ func (ec *executionContext) unmarshalOPageInput2ᚖgithubᚗcomᚋsourᚑisᚋev
return &res, graphql.ErrorOnPath(ctx, err) return &res, graphql.ErrorOnPath(ctx, err)
} }
func (ec *executionContext) marshalOPostEvent2ᚖgithubᚗcomᚋsourisᚋevᚋappᚋmsgbusᚐPostEvent(ctx context.Context, sel ast.SelectionSet, v *msgbus.PostEvent) graphql.Marshaler { func (ec *executionContext) marshalOPostEvent2ᚖgoᚗsourisᚋevᚋappᚋmsgbusᚐPostEvent(ctx context.Context, sel ast.SelectionSet, v *msgbus.PostEvent) graphql.Marshaler {
if v == nil { if v == nil {
return graphql.Null return graphql.Null
} }
return ec._PostEvent(ctx, sel, v) return ec._PostEvent(ctx, sel, v)
} }
func (ec *executionContext) marshalOSaltyUser2ᚖgithubᚗcomᚋsourisᚋevᚋappᚋsaltyᚐSaltyUser(ctx context.Context, sel ast.SelectionSet, v *salty.SaltyUser) graphql.Marshaler { func (ec *executionContext) marshalOSaltyUser2ᚖgoᚗsourisᚋevᚋappᚋsaltyᚐSaltyUser(ctx context.Context, sel ast.SelectionSet, v *salty.SaltyUser) graphql.Marshaler {
if v == nil { if v == nil {
return graphql.Null return graphql.Null
} }

View File

@@ -30,7 +30,7 @@ func (r *queryResolver) Events(ctx context.Context, streamID string, paging *gql
} }
// // foo // // foo
func (r *queryResolver) Posts(ctx context.Context, streamID string, paging *gql.PageInput) (*gql.Connection, error) { func (r *queryResolver) Posts(ctx context.Context, name, tag string, paging *gql.PageInput) (*gql.Connection, error) {
panic("not implemented") panic("not implemented")
} }
@@ -45,7 +45,7 @@ func (r *subscriptionResolver) EventAdded(ctx context.Context, streamID string,
} }
// // foo // // foo
func (r *subscriptionResolver) PostAdded(ctx context.Context, streamID string, after int64) (<-chan *msgbus.PostEvent, error) { func (r *subscriptionResolver) PostAdded(ctx context.Context, name, tag string, after int64) (<-chan *msgbus.PostEvent, error) {
panic("not implemented") panic("not implemented")
} }

View File

@@ -33,24 +33,11 @@ func (a *Agg) ApplyEvent(lis ...event.Event) {
type ValueApplied struct { type ValueApplied struct {
Value string Value string
eventMeta event.Meta event.IsEvent
} }
var _ event.Event = (*ValueApplied)(nil) var _ event.Event = (*ValueApplied)(nil)
func (e *ValueApplied) EventMeta() event.Meta {
if e == nil {
return event.Meta{}
}
return e.eventMeta
}
func (e *ValueApplied) SetEventMeta(m event.Meta) {
if e != nil {
e.eventMeta = m
}
}
func (e *ValueApplied) MarshalBinary() ([]byte, error) { func (e *ValueApplied) MarshalBinary() ([]byte, error) {
return json.Marshal(e) return json.Marshal(e)
} }

View File

@@ -5,7 +5,6 @@ import (
"context" "context"
"crypto/rand" "crypto/rand"
"encoding" "encoding"
"encoding/json"
"fmt" "fmt"
"io" "io"
"strconv" "strconv"
@@ -156,25 +155,23 @@ func Init(ctx context.Context) error {
} }
type nilEvent struct { type nilEvent struct {
IsEvent
} }
func (*nilEvent) EventMeta() Meta { return Meta{} }
func (*nilEvent) SetEventMeta(eventMeta Meta) {}
var NilEvent = &nilEvent{} var NilEvent = &nilEvent{}
func (e *nilEvent) MarshalBinary() ([]byte, error) { func (e *nilEvent) MarshalBinary() ([]byte, error) {
return json.Marshal(e) return nil, nil
} }
func (e *nilEvent) UnmarshalBinary(b []byte) error { func (e *nilEvent) UnmarshalBinary(b []byte) error {
return json.Unmarshal(b, e) return nil
} }
type EventPtr struct { type EventPtr struct {
StreamID string `json:"stream_id"` StreamID string `json:"stream_id"`
Pos uint64 `json:"pos"` Pos uint64 `json:"pos"`
eventMeta Meta IsEvent
} }
var _ Event = (*EventPtr)(nil) var _ Event = (*EventPtr)(nil)
@@ -202,22 +199,6 @@ func (e *EventPtr) UnmarshalBinary(data []byte) error {
return err return err
} }
// EventMeta implements Event
func (e *EventPtr) EventMeta() Meta {
if e == nil {
return Meta{}
}
return e.eventMeta
}
// SetEventMeta implements Event
func (e *EventPtr) SetEventMeta(m Meta) {
if e == nil {
return
}
e.eventMeta = m
}
func (e *EventPtr) Values() any { func (e *EventPtr) Values() any {
return struct { return struct {
StreamID string `json:"stream_id"` StreamID string `json:"stream_id"`
@@ -229,26 +210,30 @@ func (e *EventPtr) Values() any {
} }
type FeedTruncated struct { type FeedTruncated struct {
eventMeta Meta IsEvent
}
// EventMeta implements Event
func (e *FeedTruncated) EventMeta() Meta {
if e == nil {
return Meta{}
}
return e.eventMeta
}
// SetEventMeta implements Event
func (e *FeedTruncated) SetEventMeta(m Meta) {
if e == nil {
return
}
e.eventMeta = m
} }
func (e *FeedTruncated) Values() any { func (e *FeedTruncated) Values() any {
return struct { return struct {
}{} }{}
} }
type property[T any] struct {
v T
}
type IsEvent = property[Meta]
func (p *property[T]) EventMeta() T {
if p == nil {
var t T
return t
}
return p.v
}
func (p *property[T]) SetEventMeta(x T) {
if p != nil {
p.v = x
}
}

View File

@@ -14,21 +14,9 @@ import (
type DummyEvent struct { type DummyEvent struct {
Value string Value string
eventMeta event.Meta event.IsEvent
} }
func (e *DummyEvent) EventMeta() event.Meta {
if e == nil {
return event.Meta{}
}
return e.eventMeta
}
func (e *DummyEvent) SetEventMeta(eventMeta event.Meta) {
if e == nil {
return
}
e.eventMeta = eventMeta
}
func (e *DummyEvent) MarshalBinary() ([]byte, error) { func (e *DummyEvent) MarshalBinary() ([]byte, error) {
return json.Marshal(e) return json.Marshal(e)
} }

View File

@@ -25,7 +25,7 @@ type UnknownEvent struct {
eventType string eventType string
values map[string]json.RawMessage values map[string]json.RawMessage
eventMeta Meta IsEvent
} }
var _ Event = (*UnknownEvent)(nil) var _ Event = (*UnknownEvent)(nil)
@@ -48,16 +48,16 @@ func NewUnknownEventFromValues(eventType string, meta Meta, values url.Values) *
} }
} }
return &UnknownEvent{eventType: eventType, eventMeta: meta, values: jsonValues} e := &UnknownEvent{eventType: eventType, values: jsonValues}
e.SetEventMeta(meta)
return e
} }
func NewUnknownEventFromRaw(eventType string, meta Meta, values map[string]json.RawMessage) *UnknownEvent { func NewUnknownEventFromRaw(eventType string, meta Meta, values map[string]json.RawMessage) *UnknownEvent {
return &UnknownEvent{eventType: eventType, eventMeta: meta, values: values} e := &UnknownEvent{eventType: eventType, values: values}
e.SetEventMeta(meta)
return e
} }
func (u UnknownEvent) EventMeta() Meta { return u.eventMeta }
func (u UnknownEvent) EventType() string { return u.eventType } func (u UnknownEvent) EventType() string { return u.eventType }
func (u *UnknownEvent) SetEventMeta(em Meta) {
u.eventMeta = em
}
func (u *UnknownEvent) UnmarshalBinary(b []byte) error { func (u *UnknownEvent) UnmarshalBinary(b []byte) error {
return json.Unmarshal(b, &u.values) return json.Unmarshal(b, &u.values)
} }