Skip to content

Commit

Permalink
chore: Move Option and Enumerable to immutables (sourcenetwork#939)
Browse files Browse the repository at this point in the history
Relevant issue(s)
Resolves sourcenetwork#854
Resolves sourcenetwork#853

Description
This PR adds no new code. It's simply moving or renaming things. Mainly, the Option and Enumerable types are moved the external immutable package and the UpdateEvent is moved to the events package are renamed Update.
  • Loading branch information
fredcarle authored Nov 23, 2022
1 parent 758d077 commit 6d3a58d
Show file tree
Hide file tree
Showing 53 changed files with 291 additions and 706 deletions.
3 changes: 1 addition & 2 deletions api/http/handlerfuncs.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/multiformats/go-multihash"
"github.com/pkg/errors"

"github.com/sourcenetwork/defradb/client"
corecrdt "github.com/sourcenetwork/defradb/core/crdt"
"github.com/sourcenetwork/defradb/events"
)
Expand Down Expand Up @@ -266,7 +265,7 @@ func peerIDHandler(rw http.ResponseWriter, req *http.Request) {
)
}

func subscriptionHandler(pub *events.Publisher[client.UpdateEvent], rw http.ResponseWriter, req *http.Request) {
func subscriptionHandler(pub *events.Publisher[events.Update], rw http.ResponseWriter, req *http.Request) {
flusher, ok := rw.(http.Flusher)
if !ok {
handleErr(req.Context(), rw, errors.New("streaming unsupported"), http.StatusInternalServerError)
Expand Down
11 changes: 6 additions & 5 deletions api/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"path"
"strings"

"github.com/sourcenetwork/immutable"
"golang.org/x/crypto/acme/autocert"

"github.com/sourcenetwork/defradb/client"
Expand Down Expand Up @@ -55,7 +56,7 @@ type serverOptions struct {
// ID of the server node.
peerID string
// when the value is present, the server will run with tls
tls client.Option[tlsOptions]
tls immutable.Option[tlsOptions]
// root directory for the node config.
rootDir string
}
Expand Down Expand Up @@ -132,7 +133,7 @@ func WithAddress(addr string) func(*Server) {
if ip == nil {
tlsOpt := s.options.tls.Value()
tlsOpt.domain = addr
s.options.tls = client.Some(tlsOpt)
s.options.tls = immutable.Some(tlsOpt)
}
}
}
Expand All @@ -142,7 +143,7 @@ func WithCAEmail(email string) func(*Server) {
return func(s *Server) {
tlsOpt := s.options.tls.Value()
tlsOpt.email = email
s.options.tls = client.Some(tlsOpt)
s.options.tls = immutable.Some(tlsOpt)
}
}

Expand All @@ -163,15 +164,15 @@ func WithSelfSignedCert(pubKey, privKey string) func(*Server) {
tlsOpt := s.options.tls.Value()
tlsOpt.pubKey = pubKey
tlsOpt.privKey = privKey
s.options.tls = client.Some(tlsOpt)
s.options.tls = immutable.Some(tlsOpt)
}
}

func WithTLSPort(port int) func(*Server) {
return func(s *Server) {
tlsOpt := s.options.tls.Value()
tlsOpt.port = fmt.Sprintf(":%d", port)
s.options.tls = client.Some(tlsOpt)
s.options.tls = immutable.Some(tlsOpt)
}
}

Expand Down
4 changes: 2 additions & 2 deletions client/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type DB interface {
ExecTransactionalQuery(ctx context.Context, query string, txn datastore.Txn) *QueryResult
Close(context.Context)

Events() Events
Events() events.Events

PrintDump(ctx context.Context) error
}
Expand All @@ -48,5 +48,5 @@ type GQLResult struct {

type QueryResult struct {
GQL GQLResult
Pub *events.Publisher[UpdateEvent]
Pub *events.Publisher[events.Update]
}
46 changes: 0 additions & 46 deletions client/option.go

This file was deleted.

12 changes: 6 additions & 6 deletions client/request/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

package request

import "github.com/sourcenetwork/defradb/client"
import immutables "github.com/sourcenetwork/immutable"

type Aggregate struct {
Field
Expand All @@ -20,10 +20,10 @@ type Aggregate struct {

type AggregateTarget struct {
HostName string
ChildName client.Option[string]
ChildName immutables.Option[string]

Limit client.Option[uint64]
Offset client.Option[uint64]
OrderBy client.Option[OrderBy]
Filter client.Option[Filter]
Limit immutables.Option[uint64]
Offset immutables.Option[uint64]
OrderBy immutables.Option[OrderBy]
Filter immutables.Option[Filter]
}
18 changes: 9 additions & 9 deletions client/request/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

package request

import "github.com/sourcenetwork/defradb/client"
import "github.com/sourcenetwork/immutable"

var (
_ Selection = (*CommitSelect)(nil)
Expand All @@ -19,15 +19,15 @@ var (
type CommitSelect struct {
Field

DocKey client.Option[string]
FieldName client.Option[string]
Cid client.Option[string]
Depth client.Option[uint64]
DocKey immutable.Option[string]
FieldName immutable.Option[string]
Cid immutable.Option[string]
Depth immutable.Option[uint64]

Limit client.Option[uint64]
Offset client.Option[uint64]
OrderBy client.Option[OrderBy]
GroupBy client.Option[GroupBy]
Limit immutable.Option[uint64]
Offset immutable.Option[uint64]
OrderBy immutable.Option[OrderBy]
GroupBy immutable.Option[GroupBy]

Fields []Selection
}
Expand Down
4 changes: 2 additions & 2 deletions client/request/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

package request

import "github.com/sourcenetwork/defradb/client"
import "github.com/sourcenetwork/immutable"

// Field implements Selection
type Field struct {
Name string
Alias client.Option[string]
Alias immutable.Option[string]
}
6 changes: 3 additions & 3 deletions client/request/mutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

package request

import "github.com/sourcenetwork/defradb/client"
import "github.com/sourcenetwork/immutable"

type MutationType int

Expand All @@ -35,8 +35,8 @@ type Mutation struct {
// if this mutation is on an object.
Collection string

IDs client.Option[[]string]
Filter client.Option[Filter]
IDs immutable.Option[[]string]
Filter immutable.Option[Filter]
Data string

Fields []Selection
Expand Down
20 changes: 12 additions & 8 deletions client/request/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@

package request

import "github.com/sourcenetwork/defradb/client"
import (
"github.com/sourcenetwork/immutable"

"github.com/sourcenetwork/defradb/client"
)

type SelectionType int

Expand All @@ -26,17 +30,17 @@ const (
type Select struct {
Field

DocKeys client.Option[[]string]
CID client.Option[string]
DocKeys immutable.Option[[]string]
CID immutable.Option[string]

// Root is the top level query parsed type
Root SelectionType

Limit client.Option[uint64]
Offset client.Option[uint64]
OrderBy client.Option[OrderBy]
GroupBy client.Option[GroupBy]
Filter client.Option[Filter]
Limit immutable.Option[uint64]
Offset immutable.Option[uint64]
OrderBy immutable.Option[OrderBy]
GroupBy immutable.Option[GroupBy]
Filter immutable.Option[Filter]

Fields []Selection
}
Expand Down
8 changes: 4 additions & 4 deletions client/request/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
package request

import (
"github.com/sourcenetwork/defradb/client"
"github.com/sourcenetwork/immutable"
)

// ObjectSubscription is a field on the SubscriptionType
Expand All @@ -23,7 +23,7 @@ type ObjectSubscription struct {
// Collection is the target collection name
Collection string

Filter client.Option[Filter]
Filter immutable.Option[Filter]

Fields []Selection
}
Expand All @@ -36,8 +36,8 @@ func (m ObjectSubscription) ToSelect(docKey, cid string) *Select {
Name: m.Collection,
Alias: m.Alias,
},
DocKeys: client.Some([]string{docKey}),
CID: client.Some(cid),
DocKeys: immutable.Some([]string{docKey}),
CID: immutable.Some(cid),
Fields: m.Fields,
Filter: m.Filter,
}
Expand Down
11 changes: 6 additions & 5 deletions connor/eq.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import (
"reflect"
"time"

"github.com/sourcenetwork/defradb/client"
"github.com/sourcenetwork/immutable"

"github.com/sourcenetwork/defradb/connor/numbers"
ctime "github.com/sourcenetwork/defradb/connor/time"
"github.com/sourcenetwork/defradb/core"
Expand All @@ -27,25 +28,25 @@ func eq(condition, data any) (bool, error) {
}
return false, nil

case client.Option[bool]:
case immutable.Option[bool]:
if !arr.HasValue() {
return condition == nil, nil
}
data = arr.Value()

case client.Option[int64]:
case immutable.Option[int64]:
if !arr.HasValue() {
return condition == nil, nil
}
data = arr.Value()

case client.Option[float64]:
case immutable.Option[float64]:
if !arr.HasValue() {
return condition == nil, nil
}
data = arr.Value()

case client.Option[string]:
case immutable.Option[string]:
if !arr.HasValue() {
return condition == nil, nil
}
Expand Down
7 changes: 4 additions & 3 deletions core/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ Package core provides commonly shared interfaces and building blocks.
package core

import (
"github.com/sourcenetwork/defradb/client"
"github.com/sourcenetwork/immutable"

"github.com/sourcenetwork/defradb/client/request"
)

Expand Down Expand Up @@ -86,7 +87,7 @@ type mappingTypeInfo struct {

type DocumentMapping struct {
// The type information for the object, if provided.
typeInfo client.Option[mappingTypeInfo]
typeInfo immutable.Option[mappingTypeInfo]

// The set of fields that should be rendered.
//
Expand Down Expand Up @@ -230,7 +231,7 @@ func (mapping *DocumentMapping) Add(index int, name string) {
func (mapping *DocumentMapping) SetTypeName(typeName string) {
index := mapping.GetNextIndex()
mapping.Add(index, request.TypeNameFieldName)
mapping.typeInfo = client.Some(mappingTypeInfo{
mapping.typeInfo = immutable.Some(mappingTypeInfo{
Index: index,
Name: typeName,
})
Expand Down
Loading

0 comments on commit 6d3a58d

Please sign in to comment.