Skip to content

Commit

Permalink
change to external immubable package
Browse files Browse the repository at this point in the history
  • Loading branch information
fredcarle committed Nov 23, 2022
1 parent 8288b62 commit 54e8b6b
Show file tree
Hide file tree
Showing 44 changed files with 242 additions and 737 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
12 changes: 6 additions & 6 deletions api/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import (
"path"
"strings"

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

"github.com/sourcenetwork/defradb/client"
"github.com/sourcenetwork/defradb/errors"
"github.com/sourcenetwork/defradb/immutables"
"github.com/sourcenetwork/defradb/logging"
)

Expand Down Expand Up @@ -56,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 immutables.Option[tlsOptions]
tls immutable.Option[tlsOptions]
// root directory for the node config.
rootDir string
}
Expand Down Expand Up @@ -133,7 +133,7 @@ func WithAddress(addr string) func(*Server) {
if ip == nil {
tlsOpt := s.options.tls.Value()
tlsOpt.domain = addr
s.options.tls = immutables.Some(tlsOpt)
s.options.tls = immutable.Some(tlsOpt)
}
}
}
Expand All @@ -143,7 +143,7 @@ func WithCAEmail(email string) func(*Server) {
return func(s *Server) {
tlsOpt := s.options.tls.Value()
tlsOpt.email = email
s.options.tls = immutables.Some(tlsOpt)
s.options.tls = immutable.Some(tlsOpt)
}
}

Expand All @@ -164,15 +164,15 @@ func WithSelfSignedCert(pubKey, privKey string) func(*Server) {
tlsOpt := s.options.tls.Value()
tlsOpt.pubKey = pubKey
tlsOpt.privKey = privKey
s.options.tls = immutables.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 = immutables.Some(tlsOpt)
s.options.tls = immutable.Some(tlsOpt)
}
}

Expand Down
2 changes: 1 addition & 1 deletion client/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ type GQLResult struct {

type QueryResult struct {
GQL GQLResult
Pub *events.Publisher[UpdateEvent]
Pub *events.Publisher[events.Update]
}
2 changes: 1 addition & 1 deletion 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/immutables"
import immutables "github.com/sourcenetwork/immutable"

type Aggregate struct {
Field
Expand Down
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/immutables"
import "github.com/sourcenetwork/immutable"

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

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

Limit immutables.Option[uint64]
Offset immutables.Option[uint64]
OrderBy immutables.Option[OrderBy]
GroupBy immutables.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/immutables"
import "github.com/sourcenetwork/immutable"

// Field implements Selection
type Field struct {
Name string
Alias immutables.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/immutables"
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 immutables.Option[[]string]
Filter immutables.Option[Filter]
IDs immutable.Option[[]string]
Filter immutable.Option[Filter]
Data string

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

import (
"github.com/sourcenetwork/immutable"

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

type SelectionType int
Expand All @@ -29,17 +30,17 @@ const (
type Select struct {
Field

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

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

Limit immutables.Option[uint64]
Offset immutables.Option[uint64]
OrderBy immutables.Option[OrderBy]
GroupBy immutables.Option[GroupBy]
Filter immutables.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,10 +4,11 @@ import (
"reflect"
"time"

"github.com/sourcenetwork/immutable"

"github.com/sourcenetwork/defradb/connor/numbers"
ctime "github.com/sourcenetwork/defradb/connor/time"
"github.com/sourcenetwork/defradb/core"
"github.com/sourcenetwork/defradb/immutables"
)

// eq is an operator which performs object equality
Expand All @@ -27,25 +28,25 @@ func eq(condition, data any) (bool, error) {
}
return false, nil

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

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

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

case immutables.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,8 +14,9 @@ Package core provides commonly shared interfaces and building blocks.
package core

import (
"github.com/sourcenetwork/immutable"

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

const DocKeyFieldIndex int = 0
Expand Down Expand Up @@ -86,7 +87,7 @@ type mappingTypeInfo struct {

type DocumentMapping struct {
// The type information for the object, if provided.
typeInfo immutables.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 = immutables.Some(mappingTypeInfo{
mapping.typeInfo = immutable.Some(mappingTypeInfo{
Index: index,
Name: typeName,
})
Expand Down
4 changes: 3 additions & 1 deletion core/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ package core
import (
"context"

"github.com/sourcenetwork/immutable"

"github.com/sourcenetwork/defradb/client"
"github.com/sourcenetwork/defradb/client/request"
)
Expand Down Expand Up @@ -40,7 +42,7 @@ type Parser interface {
Parse(request string) (*request.Request, []error)

// NewFilterFromString creates a new filter from a string.
NewFilterFromString(collectionType string, body string) (client.Option[request.Filter], error)
NewFilterFromString(collectionType string, body string) (immutable.Option[request.Filter], error)

// Adds the given schema to this parser's model.
AddSchema(ctx context.Context, schema string) error
Expand Down
8 changes: 4 additions & 4 deletions db/collection_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"strings"

cbor "github.com/fxamacker/cbor/v2"
"github.com/sourcenetwork/immutable"
"github.com/valyala/fastjson"

"github.com/sourcenetwork/defradb/client"
Expand All @@ -23,7 +24,6 @@ import (
"github.com/sourcenetwork/defradb/datastore"
"github.com/sourcenetwork/defradb/errors"
"github.com/sourcenetwork/defradb/events"
"github.com/sourcenetwork/defradb/immutables"
"github.com/sourcenetwork/defradb/planner"
)

Expand Down Expand Up @@ -594,7 +594,7 @@ func (c *collection) makeSelectionQuery(
txn datastore.Txn,
filter any,
) (planner.Query, error) {
var f immutables.Option[request.Filter]
var f immutable.Option[request.Filter]
var err error
switch fval := filter.(type) {
case string:
Expand All @@ -606,7 +606,7 @@ func (c *collection) makeSelectionQuery(
if err != nil {
return nil, err
}
case immutables.Option[request.Filter]:
case immutable.Option[request.Filter]:
f = fval
default:
return nil, errors.New("invalid filter")
Expand All @@ -631,7 +631,7 @@ func (c *collection) makeSelectionQuery(
})
}

func (c *collection) makeSelectLocal(filter immutables.Option[request.Filter]) (*request.Select, error) {
func (c *collection) makeSelectLocal(filter immutable.Option[request.Filter]) (*request.Select, error) {
slct := &request.Select{
Field: request.Field{
Name: c.Name(),
Expand Down
7 changes: 3 additions & 4 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@ import (
"sync"

ds "github.com/ipfs/go-datastore"
"github.com/ipfs/go-datastore/query"
dsq "github.com/ipfs/go-datastore/query"
blockstore "github.com/ipfs/go-ipfs-blockstore"
"github.com/sourcenetwork/immutable"

"github.com/sourcenetwork/defradb/client"
"github.com/sourcenetwork/defradb/core"
"github.com/sourcenetwork/defradb/datastore"
"github.com/sourcenetwork/defradb/errors"
"github.com/sourcenetwork/defradb/events"
"github.com/sourcenetwork/defradb/immutables"
"github.com/sourcenetwork/defradb/logging"
"github.com/sourcenetwork/defradb/merkle/crdt"
"github.com/sourcenetwork/defradb/query/graphql"
Expand Down Expand Up @@ -75,7 +74,7 @@ const updateEventBufferSize = 100
func WithUpdateEvents() Option {
return func(db *db) {
db.events = events.Events{
Updates: immutables.Some(events.New[events.Update](0, updateEventBufferSize)),
Updates: immutable.Some(events.New[events.Update](0, updateEventBufferSize)),
}
}
}
Expand Down Expand Up @@ -197,7 +196,7 @@ func (db *db) Close(ctx context.Context) {
}

func printStore(ctx context.Context, store datastore.DSReaderWriter) error {
q := query.Query{
q := dsq.Query{
Prefix: "",
KeysOnly: false,
Orders: []dsq.Order{dsq.OrderByKey{}},
Expand Down
Loading

0 comments on commit 54e8b6b

Please sign in to comment.