diff --git a/api/http/handlerfuncs.go b/api/http/handlerfuncs.go index e12fc59153..ab6b9a85ad 100644 --- a/api/http/handlerfuncs.go +++ b/api/http/handlerfuncs.go @@ -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" ) @@ -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) diff --git a/api/http/server.go b/api/http/server.go index 3ab61182f2..52fa35ed3b 100644 --- a/api/http/server.go +++ b/api/http/server.go @@ -19,6 +19,7 @@ import ( "path" "strings" + "github.com/sourcenetwork/immutable" "golang.org/x/crypto/acme/autocert" "github.com/sourcenetwork/defradb/client" @@ -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 } @@ -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) } } } @@ -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) } } @@ -163,7 +164,7 @@ 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) } } @@ -171,7 +172,7 @@ 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) } } diff --git a/client/db.go b/client/db.go index a101320657..356652d99d 100644 --- a/client/db.go +++ b/client/db.go @@ -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 } @@ -48,5 +48,5 @@ type GQLResult struct { type QueryResult struct { GQL GQLResult - Pub *events.Publisher[UpdateEvent] + Pub *events.Publisher[events.Update] } diff --git a/client/option.go b/client/option.go deleted file mode 100644 index 55d6720dc2..0000000000 --- a/client/option.go +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2022 Democratized Data Foundation -// -// Use of this software is governed by the Business Source License -// included in the file licenses/BSL.txt. -// -// As of the Change Date specified in that file, in accordance with -// the Business Source License, use of this software will be governed -// by the Apache License, Version 2.0, included in the file -// licenses/APL.txt. - -package client - -// Option represents an item that may or may not have a value. -type Option[T any] struct { - // If HasValue is true, this Option contains a value, if - // it is false it contains no value. - hasValue bool - - // The Value of this Option. Should be ignored if HasValue is false. - value T -} - -// Some returns an `Option` of type `T` with the given value. -func Some[T any](value T) Option[T] { - return Option[T]{ - hasValue: true, - value: value, - } -} - -// Some returns an `Option` of type `T` with no value. -func None[T any]() Option[T] { - return Option[T]{} -} - -// HasValue returns a boolean indicating whether or not this optino contains a value. If -// it returns true, this Option contains a value, if it is false it contains no value. -func (o Option[T]) HasValue() bool { - return o.hasValue -} - -// Value returns the Value of this Option. Value returned is invalid HasValue() is false -// and should be ignored. -func (o Option[T]) Value() T { - return o.value -} diff --git a/client/request/aggregate.go b/client/request/aggregate.go index 3f6ade72a7..902134b258 100644 --- a/client/request/aggregate.go +++ b/client/request/aggregate.go @@ -10,7 +10,7 @@ package request -import "github.com/sourcenetwork/defradb/client" +import immutables "github.com/sourcenetwork/immutable" type Aggregate struct { Field @@ -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] } diff --git a/client/request/commit.go b/client/request/commit.go index 725ed16ddd..d8da5e8c43 100644 --- a/client/request/commit.go +++ b/client/request/commit.go @@ -10,7 +10,7 @@ package request -import "github.com/sourcenetwork/defradb/client" +import "github.com/sourcenetwork/immutable" var ( _ Selection = (*CommitSelect)(nil) @@ -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 } diff --git a/client/request/field.go b/client/request/field.go index e139a1bc8b..578074671b 100644 --- a/client/request/field.go +++ b/client/request/field.go @@ -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] } diff --git a/client/request/mutation.go b/client/request/mutation.go index 89450fa57e..6767f22871 100644 --- a/client/request/mutation.go +++ b/client/request/mutation.go @@ -10,7 +10,7 @@ package request -import "github.com/sourcenetwork/defradb/client" +import "github.com/sourcenetwork/immutable" type MutationType int @@ -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 diff --git a/client/request/select.go b/client/request/select.go index 719b3bc686..9898dbc83b 100644 --- a/client/request/select.go +++ b/client/request/select.go @@ -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 @@ -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 } diff --git a/client/request/subscription.go b/client/request/subscription.go index bdc2afbdc9..d8361b3896 100644 --- a/client/request/subscription.go +++ b/client/request/subscription.go @@ -11,7 +11,7 @@ package request import ( - "github.com/sourcenetwork/defradb/client" + "github.com/sourcenetwork/immutable" ) // ObjectSubscription is a field on the SubscriptionType @@ -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 } @@ -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, } diff --git a/connor/eq.go b/connor/eq.go index 02dca37351..f28824de1d 100644 --- a/connor/eq.go +++ b/connor/eq.go @@ -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" @@ -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 } diff --git a/core/doc.go b/core/doc.go index dafc793ccd..f1c31592e4 100644 --- a/core/doc.go +++ b/core/doc.go @@ -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" ) @@ -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. // @@ -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, }) diff --git a/core/enumerable/concat.go b/core/enumerable/concat.go deleted file mode 100644 index 309c6019dd..0000000000 --- a/core/enumerable/concat.go +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2022 Democratized Data Foundation -// -// Use of this software is governed by the Business Source License -// included in the file licenses/BSL.txt. -// -// As of the Change Date specified in that file, in accordance with -// the Business Source License, use of this software will be governed -// by the Apache License, Version 2.0, included in the file -// licenses/APL.txt. - -package enumerable - -type enumerableConcat[T any] struct { - sources []Enumerable[T] - currentSourceIndex int -} - -// Concat takes zero to many source `Ènumerable`s and stacks them on top -// of each other, resulting in one enumerable that will iterate through all -// the values in all of the given sources. -func Concat[T any](sources ...Enumerable[T]) Enumerable[T] { - return &enumerableConcat[T]{ - sources: sources, - currentSourceIndex: 0, - } -} - -func (s *enumerableConcat[T]) Next() (bool, error) { - for { - if s.currentSourceIndex >= len(s.sources) { - return false, nil - } - - currentSource := s.sources[s.currentSourceIndex] - hasValue, err := currentSource.Next() - if err != nil { - return false, nil - } - if hasValue { - return true, nil - } - - s.currentSourceIndex += 1 - } -} - -func (s *enumerableConcat[T]) Value() T { - return s.sources[s.currentSourceIndex].Value() -} - -func (s *enumerableConcat[T]) Reset() { - s.currentSourceIndex = 0 - for _, source := range s.sources { - source.Reset() - } -} diff --git a/core/enumerable/enumerable.go b/core/enumerable/enumerable.go deleted file mode 100644 index 065e93f5ed..0000000000 --- a/core/enumerable/enumerable.go +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright 2022 Democratized Data Foundation -// -// Use of this software is governed by the Business Source License -// included in the file licenses/BSL.txt. -// -// As of the Change Date specified in that file, in accordance with -// the Business Source License, use of this software will be governed -// by the Apache License, Version 2.0, included in the file -// licenses/APL.txt. - -package enumerable - -// Enumerable represents a set of elements that can be iterated through -// multiple times. -// -// The enumerable may be a composite of multiple actions that will be lazily -// executed upon iteration, allowing the enumerable to be constructed out of a -// complex set of instructions that can be evaluated in a single iteration of the -// underlying set. -type Enumerable[T any] interface { - // Next attempts to evaluate the next item in the enumeration - allowing its - // exposure via the `Value()` function. - // - // It will return false if it has reached the end of the enumerable, and/or an - // error if one was generated during evaluation. - Next() (bool, error) - - // Value returns the current item in the enumeration. It does not progress the - // enumeration, and should be a simple getter. - // - // If the previous Next call did not return true, or Next has never been called - // the behaviour and return value of this function is undefined. - Value() T - - // Reset resets the enumerable, allowing for re-iteration. - Reset() -} - -type enumerableSlice[T any] struct { - source []T - currentIndex int - maxIndex int -} - -// New creates an `Enumerable` from the given slice. -func New[T any](source []T) Enumerable[T] { - return &enumerableSlice[T]{ - source: source, - currentIndex: -1, - maxIndex: len(source) - 1, - } -} - -func (s *enumerableSlice[T]) Next() (bool, error) { - if s.currentIndex == s.maxIndex { - return false, nil - } - s.currentIndex += 1 - return true, nil -} - -func (s *enumerableSlice[T]) Value() T { - return s.source[s.currentIndex] -} - -func (s *enumerableSlice[T]) Reset() { - s.currentIndex = -1 -} - -// ForEach iterates over the given source `Enumerable` performing the given -// action on each item. It resets the source `Enumerable` on completion. -func ForEach[T any](source Enumerable[T], action func(item T)) error { - for { - hasNext, err := source.Next() - if err != nil { - return err - } - if !hasNext { - break - } - item := source.Value() - action(item) - } - source.Reset() - return nil -} - -// OnEach iterates over the given source `Enumerable` performing the given -// action for each item yielded. It resets the source `Enumerable` on completion. -func OnEach[T any](source Enumerable[T], action func()) error { - for { - hasNext, err := source.Next() - if err != nil { - return err - } - if !hasNext { - break - } - action() - } - source.Reset() - return nil -} - -// TryGetFirst returns the first element yielded from the given source along with true. -// If no items are yielded by the source, then false with be returned. Any errors generated -// during enumeration will be yielded instead of a value. -func TryGetFirst[T any](source Enumerable[T]) (T, bool, error) { - hasNext, err := source.Next() - if err != nil || !hasNext { - var defaultV T - return defaultV, false, err - } - return source.Value(), true, nil -} diff --git a/core/enumerable/select.go b/core/enumerable/select.go deleted file mode 100644 index a946887ee1..0000000000 --- a/core/enumerable/select.go +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2022 Democratized Data Foundation -// -// Use of this software is governed by the Business Source License -// included in the file licenses/BSL.txt. -// -// As of the Change Date specified in that file, in accordance with -// the Business Source License, use of this software will be governed -// by the Apache License, Version 2.0, included in the file -// licenses/APL.txt. - -package enumerable - -type enumerableSelect[TSource any, TResult any] struct { - source Enumerable[TSource] - selector func(TSource) (TResult, error) - currentValue TResult -} - -// Select creates a new `Enumerable` that iterates through each item -// yielded by the given source and then yields the value returned by -// the given selector. -func Select[TSource any, TResult any]( - source Enumerable[TSource], - selector func(TSource) (TResult, error), -) Enumerable[TResult] { - return &enumerableSelect[TSource, TResult]{ - source: source, - selector: selector, - } -} - -func (s *enumerableSelect[TSource, TResult]) Next() (bool, error) { - hasNext, err := s.source.Next() - if !hasNext || err != nil { - return hasNext, err - } - - value := s.source.Value() - // We do this here to keep the work (and errors) in the `Next` call - result, err := s.selector(value) - if err != nil { - return false, nil - } - - s.currentValue = result - return true, nil -} - -func (s *enumerableSelect[TSource, TResult]) Value() TResult { - return s.currentValue -} - -func (s *enumerableSelect[TSource, TResult]) Reset() { - s.source.Reset() -} diff --git a/core/enumerable/skip.go b/core/enumerable/skip.go deleted file mode 100644 index 2ad62d3af0..0000000000 --- a/core/enumerable/skip.go +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2022 Democratized Data Foundation -// -// Use of this software is governed by the Business Source License -// included in the file licenses/BSL.txt. -// -// As of the Change Date specified in that file, in accordance with -// the Business Source License, use of this software will be governed -// by the Apache License, Version 2.0, included in the file -// licenses/APL.txt. - -package enumerable - -type enumerableSkip[T any] struct { - source Enumerable[T] - offset uint64 - count uint64 -} - -// Skip creates an `Enumerable` from the given `Enumerable` and offset. The returned -// `Enumerable` will skip through items until the number of items yielded from source -// excedes the give offset. -func Skip[T any](source Enumerable[T], offset uint64) Enumerable[T] { - return &enumerableSkip[T]{ - source: source, - offset: offset, - } -} - -func (s *enumerableSkip[T]) Next() (bool, error) { - for s.count < s.offset { - s.count += 1 - hasNext, err := s.source.Next() - if !hasNext || err != nil { - return hasNext, err - } - } - s.count += 1 - return s.source.Next() -} - -func (s *enumerableSkip[T]) Value() T { - return s.source.Value() -} - -func (s *enumerableSkip[T]) Reset() { - s.count = 0 - s.source.Reset() -} diff --git a/core/enumerable/sort.go b/core/enumerable/sort.go deleted file mode 100644 index c3428127d6..0000000000 --- a/core/enumerable/sort.go +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2022 Democratized Data Foundation -// -// Use of this software is governed by the Business Source License -// included in the file licenses/BSL.txt. -// -// As of the Change Date specified in that file, in accordance with -// the Business Source License, use of this software will be governed -// by the Apache License, Version 2.0, included in the file -// licenses/APL.txt. - -package enumerable - -import "sort" - -type enumerableSort[T any] struct { - source Enumerable[T] - less func(T, T) bool - capacity int - result Enumerable[T] -} - -// Sort creates an `Enumerable` from the given `Enumerable`, using the given -// less function to determine as to whether an item is less than the other in -// in terms of order. -// -// The returned `Enumerable` will enumerate the entire source -// enumerable on the first `Next` call, but will not enumerate it again unless -// reset. -func Sort[T any](source Enumerable[T], less func(T, T) bool, capacity int) Enumerable[T] { - return &enumerableSort[T]{ - source: source, - less: less, - capacity: capacity, - } -} - -func (s *enumerableSort[T]) Next() (bool, error) { - if s.result == nil { - result := make([]T, 0, s.capacity) - // Declaring an anonymous function costs, so we do it here outside of the loop - // even though it is slightly less intuitive - f := func(i int) bool { - return !s.less(result[i], s.source.Value()) - } - - for i := 0; i <= s.capacity; i++ { - hasNext, err := s.source.Next() - if err != nil { - return false, err - } - if !hasNext { - break - } - - previousLength := len(result) - indexOfFirstGreaterValue := sort.Search(previousLength, f) - value := s.source.Value() - result = append(result, value) - if indexOfFirstGreaterValue == previousLength { - // Value is the greatest, and belongs at the end - continue - } - // Shift all items to the right of the first element of greater value by - // one place. This call should not allocate. - copy(result[indexOfFirstGreaterValue+1:], result[indexOfFirstGreaterValue:]) - result[indexOfFirstGreaterValue] = value - } - - // Use the enumerableSlice for convienience - s.result = New(result) - } - - return s.result.Next() -} - -func (s *enumerableSort[T]) Value() T { - return s.result.Value() -} - -func (s *enumerableSort[T]) Reset() { - // s.result should be cleared, not reset, as Reset should - // enable the re-enumeration of the entire enumeration chain, - // not just the last step. - s.result = nil - s.source.Reset() -} diff --git a/core/enumerable/take.go b/core/enumerable/take.go deleted file mode 100644 index d9fdb51380..0000000000 --- a/core/enumerable/take.go +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2022 Democratized Data Foundation -// -// Use of this software is governed by the Business Source License -// included in the file licenses/BSL.txt. -// -// As of the Change Date specified in that file, in accordance with -// the Business Source License, use of this software will be governed -// by the Apache License, Version 2.0, included in the file -// licenses/APL.txt. - -package enumerable - -type enumerableTake[T any] struct { - source Enumerable[T] - limit uint64 - count uint64 -} - -// Take creates an `Enumerable` from the given `Enumerable` and limit. The returned -// `Enumerable` will restrict the maximum number of items yielded to the given limit. -func Take[T any](source Enumerable[T], limit uint64) Enumerable[T] { - return &enumerableTake[T]{ - source: source, - limit: limit, - } -} - -func (s *enumerableTake[T]) Next() (bool, error) { - if s.count == s.limit { - return false, nil - } - s.count += 1 - return s.source.Next() -} - -func (s *enumerableTake[T]) Value() T { - return s.source.Value() -} - -func (s *enumerableTake[T]) Reset() { - s.count = 0 - s.source.Reset() -} diff --git a/core/enumerable/where.go b/core/enumerable/where.go deleted file mode 100644 index 43b523153e..0000000000 --- a/core/enumerable/where.go +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2022 Democratized Data Foundation -// -// Use of this software is governed by the Business Source License -// included in the file licenses/BSL.txt. -// -// As of the Change Date specified in that file, in accordance with -// the Business Source License, use of this software will be governed -// by the Apache License, Version 2.0, included in the file -// licenses/APL.txt. - -package enumerable - -type enumerableWhere[T any] struct { - source Enumerable[T] - predicate func(T) (bool, error) -} - -// Where creates an `Enumerable` from the given `Enumerable` and predicate. Items in the -// source `Enumerable` must return true when passed into the predicate in order to be yielded -// from the returned `Enumerable`. -func Where[T any](source Enumerable[T], predicate func(T) (bool, error)) Enumerable[T] { - return &enumerableWhere[T]{ - source: source, - predicate: predicate, - } -} - -func (s *enumerableWhere[T]) Next() (bool, error) { - for { - hasNext, err := s.source.Next() - if !hasNext || err != nil { - return hasNext, err - } - - value := s.source.Value() - if passes, err := s.predicate(value); passes || err != nil { - return passes, err - } - } -} - -func (s *enumerableWhere[T]) Value() T { - return s.source.Value() -} - -func (s *enumerableWhere[T]) Reset() { - s.source.Reset() -} diff --git a/core/parser.go b/core/parser.go index bf895d5ce7..fd04db1db1 100644 --- a/core/parser.go +++ b/core/parser.go @@ -13,6 +13,8 @@ package core import ( "context" + "github.com/sourcenetwork/immutable" + "github.com/sourcenetwork/defradb/client" "github.com/sourcenetwork/defradb/client/request" ) @@ -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 diff --git a/db/collection.go b/db/collection.go index f66acad931..4fea5107d0 100644 --- a/db/collection.go +++ b/db/collection.go @@ -29,6 +29,7 @@ import ( "github.com/sourcenetwork/defradb/datastore" "github.com/sourcenetwork/defradb/db/base" "github.com/sourcenetwork/defradb/errors" + "github.com/sourcenetwork/defradb/events" "github.com/sourcenetwork/defradb/logging" "github.com/sourcenetwork/defradb/merkle/crdt" ) @@ -663,7 +664,7 @@ func (c *collection) save( txn.OnSuccess( func() { c.db.events.Updates.Value().Publish( - client.UpdateEvent{ + events.Update{ DocKey: doc.Key().String(), Cid: headNode.Cid(), SchemaID: c.schemaID, diff --git a/db/collection_update.go b/db/collection_update.go index 5308b5dc3c..20c556c503 100644 --- a/db/collection_update.go +++ b/db/collection_update.go @@ -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" @@ -22,6 +23,7 @@ import ( "github.com/sourcenetwork/defradb/core" "github.com/sourcenetwork/defradb/datastore" "github.com/sourcenetwork/defradb/errors" + "github.com/sourcenetwork/defradb/events" "github.com/sourcenetwork/defradb/planner" ) @@ -413,7 +415,7 @@ func (c *collection) applyMerge( txn.OnSuccess( func() { c.db.events.Updates.Value().Publish( - client.UpdateEvent{ + events.Update{ DocKey: keyStr, Cid: headNode.Cid(), SchemaID: c.schemaID, @@ -592,7 +594,7 @@ func (c *collection) makeSelectionQuery( txn datastore.Txn, filter any, ) (planner.Query, error) { - var f client.Option[request.Filter] + var f immutable.Option[request.Filter] var err error switch fval := filter.(type) { case string: @@ -604,7 +606,7 @@ func (c *collection) makeSelectionQuery( if err != nil { return nil, err } - case client.Option[request.Filter]: + case immutable.Option[request.Filter]: f = fval default: return nil, errors.New("invalid filter") @@ -629,7 +631,7 @@ func (c *collection) makeSelectionQuery( }) } -func (c *collection) makeSelectLocal(filter client.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(), diff --git a/db/db.go b/db/db.go index d14670faff..d3fddb6641 100644 --- a/db/db.go +++ b/db/db.go @@ -19,9 +19,9 @@ 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" @@ -58,7 +58,7 @@ type db struct { crdtFactory *crdt.Factory - events client.Events + events events.Events parser core.Parser @@ -73,8 +73,8 @@ const updateEventBufferSize = 100 func WithUpdateEvents() Option { return func(db *db) { - db.events = client.Events{ - Updates: client.Some(events.New[client.UpdateEvent](0, updateEventBufferSize)), + db.events = events.Events{ + Updates: immutable.Some(events.New[events.Update](0, updateEventBufferSize)), } } } @@ -172,7 +172,7 @@ func (db *db) initialize(ctx context.Context) error { return nil } -func (db *db) Events() client.Events { +func (db *db) Events() events.Events { return db.events } @@ -196,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{}}, diff --git a/db/fetcher/dag.go b/db/fetcher/dag.go index f934fb6bc6..53cfd1452f 100644 --- a/db/fetcher/dag.go +++ b/db/fetcher/dag.go @@ -17,8 +17,8 @@ import ( "github.com/ipfs/go-cid" dsq "github.com/ipfs/go-datastore/query" + "github.com/sourcenetwork/immutable" - "github.com/sourcenetwork/defradb/client" "github.com/sourcenetwork/defradb/core" "github.com/sourcenetwork/defradb/datastore" ) @@ -27,7 +27,7 @@ import ( // heads of a given doc/field type HeadFetcher struct { spans core.Spans - fieldId client.Option[string] + fieldId immutable.Option[string] kvIter dsq.Results } @@ -36,7 +36,7 @@ func (hf *HeadFetcher) Start( ctx context.Context, txn datastore.Txn, spans core.Spans, - fieldId client.Option[string], + fieldId immutable.Option[string], ) error { if len(spans.Value) == 0 { spans = core.NewSpans( diff --git a/db/fetcher/encoded_doc.go b/db/fetcher/encoded_doc.go index ad941665c2..c75ce3ac53 100644 --- a/db/fetcher/encoded_doc.go +++ b/db/fetcher/encoded_doc.go @@ -14,6 +14,7 @@ import ( "fmt" "github.com/fxamacker/cbor/v2" + "github.com/sourcenetwork/immutable" "github.com/sourcenetwork/defradb/client" "github.com/sourcenetwork/defradb/core" @@ -139,11 +140,11 @@ func (e encProperty) Decode() (client.CType, any, error) { return ctype, val, nil } -func convertNillableArray[T any](items []any) ([]client.Option[T], error) { - resultArray := make([]client.Option[T], len(items)) +func convertNillableArray[T any](items []any) ([]immutable.Option[T], error) { + resultArray := make([]immutable.Option[T], len(items)) for i, untypedValue := range items { if untypedValue == nil { - resultArray[i] = client.None[T]() + resultArray[i] = immutable.None[T]() continue } value, ok := untypedValue.(T) @@ -155,7 +156,7 @@ func convertNillableArray[T any](items []any) ([]client.Option[T], error) { *new(T), )) } - resultArray[i] = client.Some(value) + resultArray[i] = immutable.Some(value) } return resultArray, nil } @@ -163,18 +164,18 @@ func convertNillableArray[T any](items []any) ([]client.Option[T], error) { func convertNillableArrayWithConverter[TOut any]( items []any, converter func(in any) (TOut, error), -) ([]client.Option[TOut], error) { - resultArray := make([]client.Option[TOut], len(items)) +) ([]immutable.Option[TOut], error) { + resultArray := make([]immutable.Option[TOut], len(items)) for i, untypedValue := range items { if untypedValue == nil { - resultArray[i] = client.None[TOut]() + resultArray[i] = immutable.None[TOut]() continue } value, err := converter(untypedValue) if err != nil { return nil, err } - resultArray[i] = client.Some(value) + resultArray[i] = immutable.Some(value) } return resultArray, nil } diff --git a/db/fetcher/versioned.go b/db/fetcher/versioned.go index 14b9f1e94a..aec28a41b0 100644 --- a/db/fetcher/versioned.go +++ b/db/fetcher/versioned.go @@ -25,6 +25,7 @@ import ( "github.com/sourcenetwork/defradb/datastore" "github.com/sourcenetwork/defradb/db/base" "github.com/sourcenetwork/defradb/errors" + "github.com/sourcenetwork/defradb/events" "github.com/sourcenetwork/defradb/merkle/crdt" ) @@ -400,7 +401,7 @@ func (vf *VersionedFetcher) processNode( if err != nil { return err } - mcrdt, err = crdt.DefaultFactory.InstanceWithStores(vf.store, "", client.EmptyUpdateChannel, ctype, key) + mcrdt, err = crdt.DefaultFactory.InstanceWithStores(vf.store, "", events.EmptyUpdateChannel, ctype, key) if err != nil { return err } diff --git a/db/subscriptions.go b/db/subscriptions.go index 5012fcc911..c555638cb9 100644 --- a/db/subscriptions.go +++ b/db/subscriptions.go @@ -20,7 +20,7 @@ import ( ) func (db *db) checkForClientSubsciptions(r *request.Request) ( - *events.Publisher[client.UpdateEvent], + *events.Publisher[events.Update], *request.ObjectSubscription, error, ) { @@ -46,7 +46,7 @@ func (db *db) checkForClientSubsciptions(r *request.Request) ( func (db *db) handleSubscription( ctx context.Context, - pub *events.Publisher[client.UpdateEvent], + pub *events.Publisher[events.Update], r *request.ObjectSubscription, ) { for evt := range pub.Event() { diff --git a/client/events.go b/events/db_update.go similarity index 66% rename from client/events.go rename to events/db_update.go index 782acabd2b..0ae2e9f059 100644 --- a/client/events.go +++ b/events/db_update.go @@ -8,28 +8,22 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package client +package events import ( "github.com/ipfs/go-cid" ipld "github.com/ipfs/go-ipld-format" - - "github.com/sourcenetwork/defradb/events" + "github.com/sourcenetwork/immutable" ) -type UpdateChannel = Option[events.Channel[UpdateEvent]] - -var EmptyUpdateChannel = None[events.Channel[UpdateEvent]]() +type UpdateChannel = immutable.Option[Channel[Update]] -type Events struct { - // Updates publishes an `UpdateEvent` for each document written to in the database. - Updates UpdateChannel -} +var EmptyUpdateChannel = immutable.None[Channel[Update]]() // UpdateEvent represents a new DAG node added to the // append-only MerkleCRDT Clock graph of a // document or sub-field. -type UpdateEvent struct { +type Update struct { DocKey string Cid cid.Cid SchemaID string diff --git a/events/events.go b/events/events.go index f283937677..073d90aa5c 100644 --- a/events/events.go +++ b/events/events.go @@ -41,3 +41,9 @@ var _ Channel[int] = (*simpleChannel[int])(nil) func New[T any](subscriberBufferSize int, eventBufferSize int) Channel[T] { return NewSimpleChannel[T](subscriberBufferSize, eventBufferSize) } + +// Events hold the supported event types +type Events struct { + // Updates publishes an `Update` for each document written to in the database. + Updates UpdateChannel +} diff --git a/go.mod b/go.mod index cf12aae3a9..f563760554 100644 --- a/go.mod +++ b/go.mod @@ -38,6 +38,7 @@ require ( github.com/multiformats/go-varint v0.0.6 github.com/pkg/errors v0.9.1 github.com/satori/go.uuid v1.2.0 + github.com/sourcenetwork/immutable v0.2.1 github.com/spf13/cobra v1.4.0 github.com/spf13/viper v1.11.0 github.com/stretchr/testify v1.8.0 diff --git a/go.sum b/go.sum index bca9742317..066098508e 100644 --- a/go.sum +++ b/go.sum @@ -1223,6 +1223,8 @@ github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d/go.mod h1:Udh github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA= github.com/sourcenetwork/graphql-go v0.7.10-0.20221119101706-0f80a1725ab7 h1:9v7Ld9hS60HAcw/ID/yierzEjtAwkenr/5i6rGSmiXI= github.com/sourcenetwork/graphql-go v0.7.10-0.20221119101706-0f80a1725ab7/go.mod h1:3Ty9EMes+aoxl8xS0CsuCGQZ4JEsOlC5yqQDLOKoBRw= +github.com/sourcenetwork/immutable v0.2.1 h1:0SAnoiGm1XQG+xiG4gK4nmLFqTMRnQ5Y1N4WHL7vQtE= +github.com/sourcenetwork/immutable v0.2.1/go.mod h1:4jpxObkIQw8pvlIRm4ndZqf3pH9ZjYEw/UYI6GZDJww= github.com/spacemonkeygo/openssl v0.0.0-20181017203307-c2dcc5cca94a/go.mod h1:7AyxJNCJ7SBZ1MfVQCWD6Uqo2oubI2Eq2y2eqf+A5r0= github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 h1:RC6RW7j+1+HkWaX/Yh71Ee5ZHaHYt7ZP4sQgUrm6cDU= github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572/go.mod h1:w0SWMsp6j9O/dk4/ZpIhL+3CkG8ofA2vuv7k+ltqUMc= diff --git a/merkle/crdt/composite.go b/merkle/crdt/composite.go index 18df26606d..7659f626c5 100644 --- a/merkle/crdt/composite.go +++ b/merkle/crdt/composite.go @@ -19,6 +19,7 @@ import ( "github.com/sourcenetwork/defradb/core" corecrdt "github.com/sourcenetwork/defradb/core/crdt" "github.com/sourcenetwork/defradb/datastore" + "github.com/sourcenetwork/defradb/events" "github.com/sourcenetwork/defradb/merkle/clock" ) @@ -27,7 +28,7 @@ var ( func( mstore datastore.MultiStore, schemaID string, - uCh client.UpdateChannel, + uCh events.UpdateChannel, ) MerkleCRDTInitFn { return func(key core.DataStoreKey) MerkleCRDT { return NewMerkleCompositeDAG( @@ -65,7 +66,7 @@ func NewMerkleCompositeDAG( headstore datastore.DSReaderWriter, dagstore datastore.DAGStore, schemaID string, - uCh client.UpdateChannel, + uCh events.UpdateChannel, ns, key core.DataStoreKey, ) *MerkleCompositeDAG { diff --git a/merkle/crdt/factory.go b/merkle/crdt/factory.go index 62ff080a6a..8b0ec1cdb8 100644 --- a/merkle/crdt/factory.go +++ b/merkle/crdt/factory.go @@ -15,6 +15,7 @@ import ( "github.com/sourcenetwork/defradb/core" "github.com/sourcenetwork/defradb/datastore" "github.com/sourcenetwork/defradb/errors" + "github.com/sourcenetwork/defradb/events" ) var ( @@ -29,7 +30,7 @@ type MerkleCRDTInitFn func(core.DataStoreKey) MerkleCRDT type MerkleCRDTFactory func( mstore datastore.MultiStore, schemaID string, - uCh client.UpdateChannel, + uCh events.UpdateChannel, ) MerkleCRDTInitFn // Factory is a helper utility for instantiating new MerkleCRDTs. @@ -67,7 +68,7 @@ func (factory *Factory) Register(t client.CType, fn *MerkleCRDTFactory) error { // supplied with all the current stores (passed in as a datastore.MultiStore object). func (factory Factory) Instance( schemaID string, - uCh client.UpdateChannel, + uCh events.UpdateChannel, t client.CType, key core.DataStoreKey, ) (MerkleCRDT, error) { @@ -85,7 +86,7 @@ func (factory Factory) Instance( func (factory Factory) InstanceWithStores( store datastore.MultiStore, schemaID string, - uCh client.UpdateChannel, + uCh events.UpdateChannel, t client.CType, key core.DataStoreKey, ) (MerkleCRDT, error) { diff --git a/merkle/crdt/factory_test.go b/merkle/crdt/factory_test.go index 0cadfdb1bb..6445f2de8c 100644 --- a/merkle/crdt/factory_test.go +++ b/merkle/crdt/factory_test.go @@ -20,6 +20,7 @@ import ( "github.com/sourcenetwork/defradb/client" "github.com/sourcenetwork/defradb/core" "github.com/sourcenetwork/defradb/datastore" + "github.com/sourcenetwork/defradb/events" ) func newStores() datastore.MultiStore { @@ -127,7 +128,7 @@ func TestFactoryInstanceMissing(t *testing.T) { m := newStores() f := NewFactory(m) - _, err := f.Instance("", client.EmptyUpdateChannel, client.LWW_REGISTER, core.MustNewDataStoreKey("/1/0/MyKey")) + _, err := f.Instance("", events.EmptyUpdateChannel, client.LWW_REGISTER, core.MustNewDataStoreKey("/1/0/MyKey")) assert.Equal(t, err, ErrFactoryTypeNoExist) } @@ -137,7 +138,7 @@ func TestBlankFactoryInstanceWithLWWRegister(t *testing.T) { f1.Register(client.LWW_REGISTER, &lwwFactoryFn) f := f1.WithStores(m) - crdt, err := f.Instance("", client.EmptyUpdateChannel, client.LWW_REGISTER, core.MustNewDataStoreKey("/1/0/MyKey")) + crdt, err := f.Instance("", events.EmptyUpdateChannel, client.LWW_REGISTER, core.MustNewDataStoreKey("/1/0/MyKey")) assert.NoError(t, err) _, ok := crdt.(*MerkleLWWRegister) @@ -150,7 +151,7 @@ func TestBlankFactoryInstanceWithCompositeRegister(t *testing.T) { f1.Register(client.COMPOSITE, &compFactoryFn) f := f1.WithStores(m) - crdt, err := f.Instance("", client.EmptyUpdateChannel, client.COMPOSITE, core.MustNewDataStoreKey("/1/0/MyKey")) + crdt, err := f.Instance("", events.EmptyUpdateChannel, client.COMPOSITE, core.MustNewDataStoreKey("/1/0/MyKey")) assert.NoError(t, err) _, ok := crdt.(*MerkleCompositeDAG) @@ -162,7 +163,7 @@ func TestFullFactoryInstanceLWWRegister(t *testing.T) { f := NewFactory(m) f.Register(client.LWW_REGISTER, &lwwFactoryFn) - crdt, err := f.Instance("", client.EmptyUpdateChannel, client.LWW_REGISTER, core.MustNewDataStoreKey("/1/0/MyKey")) + crdt, err := f.Instance("", events.EmptyUpdateChannel, client.LWW_REGISTER, core.MustNewDataStoreKey("/1/0/MyKey")) assert.NoError(t, err) _, ok := crdt.(*MerkleLWWRegister) @@ -174,7 +175,7 @@ func TestFullFactoryInstanceCompositeRegister(t *testing.T) { f := NewFactory(m) f.Register(client.COMPOSITE, &compFactoryFn) - crdt, err := f.Instance("", client.EmptyUpdateChannel, client.COMPOSITE, core.MustNewDataStoreKey("/1/0/MyKey")) + crdt, err := f.Instance("", events.EmptyUpdateChannel, client.COMPOSITE, core.MustNewDataStoreKey("/1/0/MyKey")) assert.NoError(t, err) _, ok := crdt.(*MerkleCompositeDAG) @@ -185,7 +186,7 @@ func TestLWWRegisterFactoryFn(t *testing.T) { ctx := context.Background() m := newStores() f := NewFactory(m) // here factory is only needed to satisfy datastore.MultiStore interface - crdt := lwwFactoryFn(f, "", client.EmptyUpdateChannel)(core.MustNewDataStoreKey("/1/0/MyKey")) + crdt := lwwFactoryFn(f, "", events.EmptyUpdateChannel)(core.MustNewDataStoreKey("/1/0/MyKey")) lwwreg, ok := crdt.(*MerkleLWWRegister) assert.True(t, ok) @@ -198,7 +199,7 @@ func TestCompositeRegisterFactoryFn(t *testing.T) { ctx := context.Background() m := newStores() f := NewFactory(m) // here factory is only needed to satisfy datastore.MultiStore interface - crdt := compFactoryFn(f, "", client.EmptyUpdateChannel)(core.MustNewDataStoreKey("/1/0/MyKey")) + crdt := compFactoryFn(f, "", events.EmptyUpdateChannel)(core.MustNewDataStoreKey("/1/0/MyKey")) merkleReg, ok := crdt.(*MerkleCompositeDAG) assert.True(t, ok) diff --git a/merkle/crdt/lwwreg.go b/merkle/crdt/lwwreg.go index d8bb267e36..c010fa71f5 100644 --- a/merkle/crdt/lwwreg.go +++ b/merkle/crdt/lwwreg.go @@ -19,12 +19,13 @@ import ( "github.com/sourcenetwork/defradb/core" corecrdt "github.com/sourcenetwork/defradb/core/crdt" "github.com/sourcenetwork/defradb/datastore" + "github.com/sourcenetwork/defradb/events" "github.com/sourcenetwork/defradb/merkle/clock" ) var ( lwwFactoryFn = MerkleCRDTFactory( - func(mstore datastore.MultiStore, _ string, _ client.UpdateChannel) MerkleCRDTInitFn { + func(mstore datastore.MultiStore, _ string, _ events.UpdateChannel) MerkleCRDTInitFn { return func(key core.DataStoreKey) MerkleCRDT { return NewMerkleLWWRegister( mstore.Datastore(), diff --git a/merkle/crdt/merklecrdt.go b/merkle/crdt/merklecrdt.go index e2df208c7c..0cbb2d768f 100644 --- a/merkle/crdt/merklecrdt.go +++ b/merkle/crdt/merklecrdt.go @@ -15,8 +15,8 @@ import ( ipld "github.com/ipfs/go-ipld-format" - "github.com/sourcenetwork/defradb/client" "github.com/sourcenetwork/defradb/core" + "github.com/sourcenetwork/defradb/events" "github.com/sourcenetwork/defradb/logging" ) @@ -43,7 +43,7 @@ type baseMerkleCRDT struct { clock core.MerkleClock crdt core.ReplicatedData - updateChannel client.UpdateChannel + updateChannel events.UpdateChannel } func (base *baseMerkleCRDT) Clock() core.MerkleClock { diff --git a/net/client.go b/net/client.go index e82ec09990..692cbb40a5 100644 --- a/net/client.go +++ b/net/client.go @@ -21,6 +21,7 @@ import ( "github.com/sourcenetwork/defradb/client" "github.com/sourcenetwork/defradb/errors" + "github.com/sourcenetwork/defradb/events" "github.com/sourcenetwork/defradb/logging" pb "github.com/sourcenetwork/defradb/net/pb" ) @@ -33,7 +34,7 @@ var ( // pushLog creates a pushLog request and sends it to another node // over libp2p grpc connection -func (s *server) pushLog(ctx context.Context, evt client.UpdateEvent, pid peer.ID) error { +func (s *server) pushLog(ctx context.Context, evt events.Update, pid peer.ID) error { dockey, err := client.NewDocKeyFromString(evt.DocKey) if err != nil { return errors.Wrap("failed to get DocKey from broadcast message", err) diff --git a/net/peer.go b/net/peer.go index b2c42d0a1b..398cb76595 100644 --- a/net/peer.go +++ b/net/peer.go @@ -38,6 +38,7 @@ import ( "github.com/sourcenetwork/defradb/core" corenet "github.com/sourcenetwork/defradb/core/net" "github.com/sourcenetwork/defradb/errors" + "github.com/sourcenetwork/defradb/events" "github.com/sourcenetwork/defradb/logging" "github.com/sourcenetwork/defradb/merkle/clock" pb "github.com/sourcenetwork/defradb/net/pb" @@ -53,7 +54,7 @@ type Peer struct { //config?? db client.DB - updateChannel chan client.UpdateEvent + updateChannel chan events.Update host host.Host dht routing.Routing @@ -395,7 +396,7 @@ func (p *Peer) AddReplicator( continue } - evt := client.UpdateEvent{ + evt := events.Update{ DocKey: dockey.ToString(), Cid: c, SchemaID: col.SchemaID(), @@ -418,7 +419,7 @@ func (p *Peer) AddReplicator( return pid, nil } -func (p *Peer) handleDocCreateLog(evt client.UpdateEvent) error { +func (p *Peer) handleDocCreateLog(evt events.Update) error { dockey, err := client.NewDocKeyFromString(evt.DocKey) if err != nil { return errors.Wrap("failed to get DocKey from broadcast message", err) @@ -430,7 +431,7 @@ func (p *Peer) handleDocCreateLog(evt client.UpdateEvent) error { return p.RegisterNewDocument(p.ctx, dockey, evt.Cid, evt.Block, evt.SchemaID) } -func (p *Peer) handleDocUpdateLog(evt client.UpdateEvent) error { +func (p *Peer) handleDocUpdateLog(evt events.Update) error { dockey, err := client.NewDocKeyFromString(evt.DocKey) if err != nil { return errors.Wrap("failed to get DocKey from broadcast message", err) @@ -463,7 +464,7 @@ func (p *Peer) handleDocUpdateLog(evt client.UpdateEvent) error { return nil } -func (p *Peer) pushLogToReplicators(ctx context.Context, lg client.UpdateEvent) { +func (p *Peer) pushLogToReplicators(ctx context.Context, lg events.Update) { // push to each peer (replicator) if reps, exists := p.replicators[lg.SchemaID]; exists { for pid := range reps { diff --git a/net/process.go b/net/process.go index 589b0ce61a..699ef7dca1 100644 --- a/net/process.go +++ b/net/process.go @@ -27,6 +27,7 @@ import ( "github.com/sourcenetwork/defradb/datastore" "github.com/sourcenetwork/defradb/db/base" "github.com/sourcenetwork/defradb/errors" + "github.com/sourcenetwork/defradb/events" "github.com/sourcenetwork/defradb/logging" "github.com/sourcenetwork/defradb/merkle/clock" "github.com/sourcenetwork/defradb/merkle/crdt" @@ -124,7 +125,7 @@ func initCRDTForType( key = base.MakeCollectionKey(description).WithInstanceInfo(docKey).WithFieldId(fieldID) } log.Debug(ctx, "Got CRDT Type", logging.NewKV("CType", ctype), logging.NewKV("Field", field)) - return crdt.DefaultFactory.InstanceWithStores(txn, col.SchemaID(), client.EmptyUpdateChannel, ctype, key) + return crdt.DefaultFactory.InstanceWithStores(txn, col.SchemaID(), events.EmptyUpdateChannel, ctype, key) } func decodeBlockBuffer(buf []byte, cid cid.Cid) (ipld.Node, error) { diff --git a/planner/count.go b/planner/count.go index 8323b05368..cf3acd3c38 100644 --- a/planner/count.go +++ b/planner/count.go @@ -17,9 +17,10 @@ package planner import ( "reflect" - "github.com/sourcenetwork/defradb/client" + "github.com/sourcenetwork/immutable" + "github.com/sourcenetwork/immutable/enumerable" + "github.com/sourcenetwork/defradb/core" - "github.com/sourcenetwork/defradb/core/enumerable" "github.com/sourcenetwork/defradb/planner/mapper" ) @@ -112,25 +113,25 @@ func (n *countNode) Next() (bool, error) { case []bool: arrayCount, err = countItems(array, source.Filter, source.Limit) - case []client.Option[bool]: + case []immutable.Option[bool]: arrayCount, err = countItems(array, source.Filter, source.Limit) case []int64: arrayCount, err = countItems(array, source.Filter, source.Limit) - case []client.Option[int64]: + case []immutable.Option[int64]: arrayCount, err = countItems(array, source.Filter, source.Limit) case []float64: arrayCount, err = countItems(array, source.Filter, source.Limit) - case []client.Option[float64]: + case []immutable.Option[float64]: arrayCount, err = countItems(array, source.Filter, source.Limit) case []string: arrayCount, err = countItems(array, source.Filter, source.Limit) - case []client.Option[string]: + case []immutable.Option[string]: arrayCount, err = countItems(array, source.Filter, source.Limit) } if err != nil { diff --git a/planner/mapper/commitSelect.go b/planner/mapper/commitSelect.go index 0d15e7958d..c4190eb272 100644 --- a/planner/mapper/commitSelect.go +++ b/planner/mapper/commitSelect.go @@ -10,7 +10,7 @@ package mapper -import "github.com/sourcenetwork/defradb/client" +import "github.com/sourcenetwork/immutable" // CommitSelect represents a commit request from a consumer. // @@ -20,16 +20,16 @@ type CommitSelect struct { Select // The key of the target document for which to get commits for. - DocKey client.Option[string] + DocKey immutable.Option[string] // The field for which commits have been requested. - FieldName client.Option[string] + FieldName immutable.Option[string] // The maximum depth to yield results for. - Depth client.Option[uint64] + Depth immutable.Option[uint64] // The parent Cid for which commit information has been requested. - Cid client.Option[string] + Cid immutable.Option[string] } func (s *CommitSelect) CloneTo(index int) Requestable { diff --git a/planner/mapper/mapper.go b/planner/mapper/mapper.go index ceada747ba..ee5e6c9ab1 100644 --- a/planner/mapper/mapper.go +++ b/planner/mapper/mapper.go @@ -16,11 +16,13 @@ import ( "reflect" "strings" + "github.com/sourcenetwork/immutable" + "github.com/sourcenetwork/immutable/enumerable" + "github.com/sourcenetwork/defradb/client" "github.com/sourcenetwork/defradb/client/request" "github.com/sourcenetwork/defradb/connor" "github.com/sourcenetwork/defradb/core" - "github.com/sourcenetwork/defradb/core/enumerable" "github.com/sourcenetwork/defradb/datastore" "github.com/sourcenetwork/defradb/errors" ) @@ -107,7 +109,7 @@ func toSelect( func resolveOrderDependencies( descriptionsRepo *DescriptionsRepo, descName string, - source client.Option[request.OrderBy], + source immutable.Option[request.OrderBy], mapping *core.DocumentMapping, existingFields *[]Requestable, ) error { @@ -628,7 +630,7 @@ func getTopLevelInfo( func resolveFilterDependencies( descriptionsRepo *DescriptionsRepo, parentCollectionName string, - source client.Option[request.Filter], + source immutable.Option[request.Filter], mapping *core.DocumentMapping, existingFields []Requestable, ) ([]Requestable, error) { @@ -831,7 +833,7 @@ func toField(index int, parsed *request.Select) Field { // ToFilter converts the given `source` request filter to a Filter using the given mapping. // // Any requestables identified by name will be converted to being identified by index instead. -func ToFilter(source client.Option[request.Filter], mapping *core.DocumentMapping) *Filter { +func ToFilter(source immutable.Option[request.Filter], mapping *core.DocumentMapping) *Filter { if !source.HasValue() { return nil } @@ -917,7 +919,7 @@ func toFilterMap( } } -func toLimit(limit client.Option[uint64], offset client.Option[uint64]) *Limit { +func toLimit(limit immutable.Option[uint64], offset immutable.Option[uint64]) *Limit { var limitValue uint64 var offsetValue uint64 if !limit.HasValue() && !offset.HasValue() { @@ -938,7 +940,7 @@ func toLimit(limit client.Option[uint64], offset client.Option[uint64]) *Limit { } } -func toGroupBy(source client.Option[request.GroupBy], mapping *core.DocumentMapping) *GroupBy { +func toGroupBy(source immutable.Option[request.GroupBy], mapping *core.DocumentMapping) *GroupBy { if !source.HasValue() { return nil } @@ -962,7 +964,7 @@ func toGroupBy(source client.Option[request.GroupBy], mapping *core.DocumentMapp } } -func toOrderBy(source client.Option[request.OrderBy], mapping *core.DocumentMapping) *OrderBy { +func toOrderBy(source immutable.Option[request.OrderBy], mapping *core.DocumentMapping) *OrderBy { if !source.HasValue() { return nil } @@ -1157,14 +1159,14 @@ type aggregateRequestTarget struct { childExternalName string // The aggregate filter specified by the consumer for this target. Optional. - filter client.Option[request.Filter] + filter immutable.Option[request.Filter] // The aggregate limit-offset specified by the consumer for this target. Optional. limit *Limit // The order in which items should be aggregated. Affects results when used with // limit. Optional. - order client.Option[request.OrderBy] + order immutable.Option[request.OrderBy] } // Returns the source of the aggregate as requested by the consumer @@ -1273,7 +1275,7 @@ func tryGetTarget( // to the given Select. func appendNotNilFilter(field *aggregateRequestTarget, childField string) { if !field.filter.HasValue() || field.filter.Value().Conditions == nil { - field.filter = client.Some( + field.filter = immutable.Some( request.Filter{ Conditions: map[string]any{}, }, diff --git a/planner/mapper/select.go b/planner/mapper/select.go index c7e78e30ca..2696c0ca82 100644 --- a/planner/mapper/select.go +++ b/planner/mapper/select.go @@ -11,7 +11,8 @@ package mapper import ( - "github.com/sourcenetwork/defradb/client" + "github.com/sourcenetwork/immutable" + "github.com/sourcenetwork/defradb/core" ) @@ -27,7 +28,7 @@ type Select struct { core.DocumentMapping // A commit identifier that can be specified to request data at a given time. - Cid client.Option[string] + Cid immutable.Option[string] // The name of the collection that this Select selects data from. CollectionName string diff --git a/planner/mapper/targetable.go b/planner/mapper/targetable.go index ee8e84e8ff..e5ba30600e 100644 --- a/planner/mapper/targetable.go +++ b/planner/mapper/targetable.go @@ -11,7 +11,8 @@ package mapper import ( - "github.com/sourcenetwork/defradb/client" + "github.com/sourcenetwork/immutable" + "github.com/sourcenetwork/defradb/connor" "github.com/sourcenetwork/defradb/core" ) @@ -132,7 +133,7 @@ type Targetable struct { // A optional collection of docKeys that can be specified to restrict results // to belonging to this set. - DocKeys client.Option[[]string] + DocKeys immutable.Option[[]string] // An optional filter, that can be specified to restrict results to documents // that satisfies all of its conditions. diff --git a/planner/select.go b/planner/select.go index 1895a2b2e9..02ba59ea88 100644 --- a/planner/select.go +++ b/planner/select.go @@ -12,8 +12,8 @@ package planner import ( cid "github.com/ipfs/go-cid" + "github.com/sourcenetwork/immutable" - "github.com/sourcenetwork/defradb/client" "github.com/sourcenetwork/defradb/client/request" "github.com/sourcenetwork/defradb/core" "github.com/sourcenetwork/defradb/db/base" @@ -116,7 +116,7 @@ type selectNode struct { // are defined in the subtype scan node. filter *mapper.Filter - docKeys client.Option[[]string] + docKeys immutable.Option[[]string] parsed *mapper.Select groupSelects []*mapper.Select @@ -293,7 +293,7 @@ func (n *selectNode) initFields(parsed *mapper.Select) ([]aggregateNode, error) // of that Target version we are querying. // So instead of a LatestCommit subquery, we need // a OneCommit subquery, with the supplied parameters. - commitSlct.DocKey = client.Some(parsed.DocKeys.Value()[0]) // @todo check length + commitSlct.DocKey = immutable.Some(parsed.DocKeys.Value()[0]) // @todo check length commitSlct.Cid = parsed.Cid } diff --git a/planner/sum.go b/planner/sum.go index 2458f0fd5f..8e1e4a5a32 100644 --- a/planner/sum.go +++ b/planner/sum.go @@ -13,10 +13,12 @@ package planner import ( "fmt" + "github.com/sourcenetwork/immutable" + "github.com/sourcenetwork/immutable/enumerable" + "github.com/sourcenetwork/defradb/client" "github.com/sourcenetwork/defradb/client/request" "github.com/sourcenetwork/defradb/core" - "github.com/sourcenetwork/defradb/core/enumerable" "github.com/sourcenetwork/defradb/errors" "github.com/sourcenetwork/defradb/planner/mapper" ) @@ -229,12 +231,12 @@ func (n *sumNode) Next() (bool, error) { }, ) - case []client.Option[int64]: + case []immutable.Option[int64]: collectionSum, err = sumItems( childCollection, &source, lessO[int64], - func(childItem client.Option[int64]) float64 { + func(childItem immutable.Option[int64]) float64 { if !childItem.HasValue() { return 0 } @@ -252,12 +254,12 @@ func (n *sumNode) Next() (bool, error) { }, ) - case []client.Option[float64]: + case []immutable.Option[float64]: collectionSum, err = sumItems( childCollection, &source, lessO[float64], - func(childItem client.Option[float64]) float64 { + func(childItem immutable.Option[float64]) float64 { if !childItem.HasValue() { return 0 } @@ -340,7 +342,7 @@ func lessN[T number](a T, b T) bool { return a < b } -func lessO[T number](a client.Option[T], b client.Option[T]) bool { +func lessO[T number](a immutable.Option[T], b immutable.Option[T]) bool { if !a.HasValue() { return true } diff --git a/query/graphql/parser.go b/query/graphql/parser.go index 24e42e517f..c94fc6693d 100644 --- a/query/graphql/parser.go +++ b/query/graphql/parser.go @@ -14,15 +14,16 @@ import ( "context" "strings" + gql "github.com/graphql-go/graphql" + gqlp "github.com/graphql-go/graphql/language/parser" + "github.com/graphql-go/graphql/language/source" + "github.com/sourcenetwork/immutable" + "github.com/sourcenetwork/defradb/client" "github.com/sourcenetwork/defradb/client/request" "github.com/sourcenetwork/defradb/core" defrap "github.com/sourcenetwork/defradb/query/graphql/parser" "github.com/sourcenetwork/defradb/query/graphql/schema" - - gql "github.com/graphql-go/graphql" - gqlp "github.com/graphql-go/graphql/language/parser" - "github.com/graphql-go/graphql/language/source" ) var _ core.Parser = (*parser)(nil) @@ -102,6 +103,6 @@ func (p *parser) AddSchema(ctx context.Context, schema string) error { return err } -func (p *parser) NewFilterFromString(collectionType string, body string) (client.Option[request.Filter], error) { +func (p *parser) NewFilterFromString(collectionType string, body string) (immutable.Option[request.Filter], error) { return defrap.NewFilterFromString(*p.schemaManager.Schema(), collectionType, body) } diff --git a/query/graphql/parser/commit.go b/query/graphql/parser/commit.go index cd7c3b5a0d..85e23092d0 100644 --- a/query/graphql/parser/commit.go +++ b/query/graphql/parser/commit.go @@ -15,8 +15,8 @@ import ( gql "github.com/graphql-go/graphql" "github.com/graphql-go/graphql/language/ast" + "github.com/sourcenetwork/immutable" - "github.com/sourcenetwork/defradb/client" "github.com/sourcenetwork/defradb/client/request" "github.com/sourcenetwork/defradb/core" ) @@ -33,20 +33,20 @@ func parseCommitSelect(schema gql.Schema, parent *gql.Object, field *ast.Field) prop := argument.Name.Value if prop == request.DocKey { raw := argument.Value.(*ast.StringValue) - commit.DocKey = client.Some(raw.Value) + commit.DocKey = immutable.Some(raw.Value) } else if prop == request.Cid { raw := argument.Value.(*ast.StringValue) - commit.Cid = client.Some(raw.Value) + commit.Cid = immutable.Some(raw.Value) } else if prop == request.FieldName { raw := argument.Value.(*ast.StringValue) - commit.FieldName = client.Some(raw.Value) + commit.FieldName = immutable.Some(raw.Value) } else if prop == request.OrderClause { obj := argument.Value.(*ast.ObjectValue) cond, err := ParseConditionsInOrder(obj) if err != nil { return nil, err } - commit.OrderBy = client.Some( + commit.OrderBy = immutable.Some( request.OrderBy{ Conditions: cond, }, @@ -57,21 +57,21 @@ func parseCommitSelect(schema gql.Schema, parent *gql.Object, field *ast.Field) if err != nil { return nil, err } - commit.Limit = client.Some(limit) + commit.Limit = immutable.Some(limit) } else if prop == request.OffsetClause { val := argument.Value.(*ast.IntValue) offset, err := strconv.ParseUint(val.Value, 10, 64) if err != nil { return nil, err } - commit.Offset = client.Some(offset) + commit.Offset = immutable.Some(offset) } else if prop == request.DepthClause { raw := argument.Value.(*ast.IntValue) depth, err := strconv.ParseUint(raw.Value, 10, 64) if err != nil { return nil, err } - commit.Depth = client.Some(depth) + commit.Depth = immutable.Some(depth) } else if prop == request.GroupByClause { obj := argument.Value.(*ast.ListValue) fields := []string{} @@ -79,7 +79,7 @@ func parseCommitSelect(schema gql.Schema, parent *gql.Object, field *ast.Field) fields = append(fields, v.GetValue().(string)) } - commit.GroupBy = client.Some( + commit.GroupBy = immutable.Some( request.GroupBy{ Fields: fields, }, @@ -92,11 +92,11 @@ func parseCommitSelect(schema gql.Schema, parent *gql.Object, field *ast.Field) // Depth is not exposed as an input parameter for latestCommits, // so we can blindly set it here without worrying about existing // values - commit.Depth = client.Some(uint64(1)) + commit.Depth = immutable.Some(uint64(1)) if !commit.FieldName.HasValue() { // latest commits defaults to composite commits only at the moment - commit.FieldName = client.Some(core.COMPOSITE_NAMESPACE) + commit.FieldName = immutable.Some(core.COMPOSITE_NAMESPACE) } } diff --git a/query/graphql/parser/filter.go b/query/graphql/parser/filter.go index ad6bb4ffc1..9b421de203 100644 --- a/query/graphql/parser/filter.go +++ b/query/graphql/parser/filter.go @@ -18,8 +18,8 @@ import ( "github.com/graphql-go/graphql/language/ast" gqlp "github.com/graphql-go/graphql/language/parser" gqls "github.com/graphql-go/graphql/language/source" + "github.com/sourcenetwork/immutable" - "github.com/sourcenetwork/defradb/client" "github.com/sourcenetwork/defradb/client/request" "github.com/sourcenetwork/defradb/errors" ) @@ -28,36 +28,39 @@ import ( // NewFilter parses the given GraphQL ObjectValue AST type // and extracts all the filter conditions into a usable map. -func NewFilter(stmt *ast.ObjectValue, inputType gql.Input) (client.Option[request.Filter], error) { +func NewFilter(stmt *ast.ObjectValue, inputType gql.Input) (immutable.Option[request.Filter], error) { conditions, err := ParseConditions(stmt, inputType) if err != nil { - return client.None[request.Filter](), err + return immutable.None[request.Filter](), err } - - return client.Some(request.Filter{ + return immutable.Some(request.Filter{ Conditions: conditions, }), nil } // NewFilterFromString creates a new filter from a string. -func NewFilterFromString(schema gql.Schema, collectionType string, body string) (client.Option[request.Filter], error) { +func NewFilterFromString( + schema gql.Schema, + collectionType string, + body string, +) (immutable.Option[request.Filter], error) { if !strings.HasPrefix(body, "{") { body = "{" + body + "}" } src := gqls.NewSource(&gqls.Source{Body: []byte(body)}) p, err := gqlp.MakeParser(src, gqlp.ParseOptions{}) if err != nil { - return client.None[request.Filter](), err + return immutable.None[request.Filter](), err } obj, err := gqlp.ParseObject(p, false) if err != nil { - return client.None[request.Filter](), err + return immutable.None[request.Filter](), err } parentFieldType := gql.GetFieldDef(schema, schema.QueryType(), collectionType) filterType, ok := getArgumentType(parentFieldType, request.FilterClause) if !ok { - return client.None[request.Filter](), errors.New("couldn't find filter argument type") + return immutable.None[request.Filter](), errors.New("couldn't find filter argument type") } return NewFilter(obj, filterType) } diff --git a/query/graphql/parser/mutation.go b/query/graphql/parser/mutation.go index e5ec7d6517..3db13e6cc9 100644 --- a/query/graphql/parser/mutation.go +++ b/query/graphql/parser/mutation.go @@ -15,8 +15,8 @@ import ( gql "github.com/graphql-go/graphql" "github.com/graphql-go/graphql/language/ast" + "github.com/sourcenetwork/immutable" - "github.com/sourcenetwork/defradb/client" "github.com/sourcenetwork/defradb/client/request" "github.com/sourcenetwork/defradb/errors" ) @@ -125,7 +125,7 @@ func parseMutation(schema gql.Schema, parent *gql.Object, field *ast.Field) (*re mut.Filter = filter } else if prop == request.Id { raw := argument.Value.(*ast.StringValue) - mut.IDs = client.Some([]string{raw.Value}) + mut.IDs = immutable.Some([]string{raw.Value}) } else if prop == request.Ids { raw := argument.Value.(*ast.ListValue) ids := make([]string, len(raw.Values)) @@ -136,7 +136,7 @@ func parseMutation(schema gql.Schema, parent *gql.Object, field *ast.Field) (*re } ids[i] = id.Value } - mut.IDs = client.Some(ids) + mut.IDs = immutable.Some(ids) } } diff --git a/query/graphql/parser/query.go b/query/graphql/parser/query.go index ff3b54c9ac..78cbe4278e 100644 --- a/query/graphql/parser/query.go +++ b/query/graphql/parser/query.go @@ -15,8 +15,8 @@ import ( gql "github.com/graphql-go/graphql" "github.com/graphql-go/graphql/language/ast" + "github.com/sourcenetwork/immutable" - "github.com/sourcenetwork/defradb/client" "github.com/sourcenetwork/defradb/client/request" "github.com/sourcenetwork/defradb/errors" ) @@ -189,38 +189,38 @@ func parseSelect( slct.Filter = filter } else if prop == request.DocKey { // parse single dockey query field val := astValue.(*ast.StringValue) - slct.DocKeys = client.Some([]string{val.Value}) + slct.DocKeys = immutable.Some([]string{val.Value}) } else if prop == request.DocKeys { docKeyValues := astValue.(*ast.ListValue).Values docKeys := make([]string, len(docKeyValues)) for i, value := range docKeyValues { docKeys[i] = value.(*ast.StringValue).Value } - slct.DocKeys = client.Some(docKeys) + slct.DocKeys = immutable.Some(docKeys) } else if prop == request.Cid { // parse single CID query field val := astValue.(*ast.StringValue) - slct.CID = client.Some(val.Value) + slct.CID = immutable.Some(val.Value) } else if prop == request.LimitClause { // parse limit/offset val := astValue.(*ast.IntValue) limit, err := strconv.ParseUint(val.Value, 10, 64) if err != nil { return nil, err } - slct.Limit = client.Some(limit) + slct.Limit = immutable.Some(limit) } else if prop == request.OffsetClause { // parse limit/offset val := astValue.(*ast.IntValue) offset, err := strconv.ParseUint(val.Value, 10, 64) if err != nil { return nil, err } - slct.Offset = client.Some(offset) + slct.Offset = immutable.Some(offset) } else if prop == request.OrderClause { // parse order by obj := astValue.(*ast.ObjectValue) cond, err := ParseConditionsInOrder(obj) if err != nil { return nil, err } - slct.OrderBy = client.Some( + slct.OrderBy = immutable.Some( request.OrderBy{ Conditions: cond, }, @@ -232,7 +232,7 @@ func parseSelect( fields = append(fields, v.GetValue().(string)) } - slct.GroupBy = client.Some( + slct.GroupBy = immutable.Some( request.GroupBy{ Fields: fields, }, @@ -259,11 +259,11 @@ func parseSelect( return slct, err } -func getFieldAlias(field *ast.Field) client.Option[string] { +func getFieldAlias(field *ast.Field) immutable.Option[string] { if field.Alias == nil { - return client.None[string]() + return immutable.None[string]() } - return client.Some(field.Alias.Value) + return immutable.Some(field.Alias.Value) } func parseSelectFields( @@ -324,10 +324,10 @@ func parseAggregate(schema gql.Schema, parent *gql.Object, field *ast.Field, ind case []*ast.ObjectField: hostName := argument.Name.Value var childName string - var filter client.Option[request.Filter] - var limit client.Option[uint64] - var offset client.Option[uint64] - var order client.Option[request.OrderBy] + var filter immutable.Option[request.Filter] + var limit immutable.Option[uint64] + var offset immutable.Option[uint64] + var order immutable.Option[request.OrderBy] fieldArg, hasFieldArg := tryGet(argumentValue, request.FieldName) if hasFieldArg { @@ -368,7 +368,7 @@ func parseAggregate(schema gql.Schema, parent *gql.Object, field *ast.Field, ind if err != nil { return nil, err } - limit = client.Some(limitValue) + limit = immutable.Some(limitValue) } offsetArg, hasOffsetArg := tryGet(argumentValue, request.OffsetClause) @@ -377,7 +377,7 @@ func parseAggregate(schema gql.Schema, parent *gql.Object, field *ast.Field, ind if err != nil { return nil, err } - offset = client.Some(offsetValue) + offset = immutable.Some(offsetValue) } orderArg, hasOrderArg := tryGet(argumentValue, request.OrderClause) @@ -388,7 +388,7 @@ func parseAggregate(schema gql.Schema, parent *gql.Object, field *ast.Field, ind orderDirectionString := orderArgValue.Value orderDirection := request.OrderDirection(orderDirectionString) - order = client.Some( + order = immutable.Some( request.OrderBy{ Conditions: []request.OrderCondition{ { @@ -408,7 +408,7 @@ func parseAggregate(schema gql.Schema, parent *gql.Object, field *ast.Field, ind return nil, err } - order = client.Some( + order = immutable.Some( request.OrderBy{ Conditions: orderConditions, }, @@ -418,7 +418,7 @@ func parseAggregate(schema gql.Schema, parent *gql.Object, field *ast.Field, ind targets[i] = &request.AggregateTarget{ HostName: hostName, - ChildName: client.Some(childName), + ChildName: immutable.Some(childName), Filter: filter, Limit: limit, Offset: offset, diff --git a/tests/integration/mutation/inline_array/update/simple_test.go b/tests/integration/mutation/inline_array/update/simple_test.go index 0a8e29e6d9..370919187c 100644 --- a/tests/integration/mutation/inline_array/update/simple_test.go +++ b/tests/integration/mutation/inline_array/update/simple_test.go @@ -13,7 +13,8 @@ package update import ( "testing" - . "github.com/sourcenetwork/defradb/client" + "github.com/sourcenetwork/immutable" + testUtils "github.com/sourcenetwork/defradb/tests/integration" inlineArray "github.com/sourcenetwork/defradb/tests/integration/mutation/inline_array" ) @@ -161,8 +162,14 @@ func TestMutationInlineArrayWithNillableBooleans(t *testing.T) { }, Results: []map[string]any{ { - "Name": "John", - "IndexLikesDislikes": []Option[bool]{Some(true), Some(true), Some(false), Some(true), None[bool]()}, + "Name": "John", + "IndexLikesDislikes": []immutable.Option[bool]{ + immutable.Some(true), + immutable.Some(true), + immutable.Some(false), + immutable.Some(true), + immutable.None[bool](), + }, }, }, } @@ -336,8 +343,14 @@ func TestMutationInlineArrayWithNillableInts(t *testing.T) { }, Results: []map[string]any{ { - "Name": "John", - "TestScores": []Option[int64]{None[int64](), Some[int64](2), Some[int64](3), None[int64](), Some[int64](8)}, + "Name": "John", + "TestScores": []immutable.Option[int64]{ + immutable.None[int64](), + immutable.Some[int64](2), + immutable.Some[int64](3), + immutable.None[int64](), + immutable.Some[int64](8), + }, }, }, } @@ -488,8 +501,13 @@ func TestMutationInlineArrayWithNillableFloats(t *testing.T) { }, Results: []map[string]any{ { - "Name": "John", - "PageRatings": []Option[float64]{Some(3.1425), Some(-0.00000000001), None[float64](), Some[float64](10)}, + "Name": "John", + "PageRatings": []immutable.Option[float64]{ + immutable.Some(3.1425), + immutable.Some(-0.00000000001), + immutable.None[float64](), + immutable.Some[float64](10), + }, }, }, } @@ -647,8 +665,15 @@ func TestMutationInlineArrayWithNillableStrings(t *testing.T) { }, Results: []map[string]any{ { - "Name": "John", - "PageHeaders": []Option[string]{Some(""), Some("the previous"), None[string](), Some("empty string"), Some("blank string"), Some("hitchi")}, + "Name": "John", + "PageHeaders": []immutable.Option[string]{ + immutable.Some(""), + immutable.Some("the previous"), + immutable.None[string](), + immutable.Some("empty string"), + immutable.Some("blank string"), + immutable.Some("hitchi"), + }, }, }, } diff --git a/tests/integration/query/inline_array/simple_test.go b/tests/integration/query/inline_array/simple_test.go index a80419fa98..619c7ad364 100644 --- a/tests/integration/query/inline_array/simple_test.go +++ b/tests/integration/query/inline_array/simple_test.go @@ -13,7 +13,8 @@ package inline_array import ( "testing" - . "github.com/sourcenetwork/defradb/client" + "github.com/sourcenetwork/immutable" + testUtils "github.com/sourcenetwork/defradb/tests/integration" ) @@ -76,7 +77,7 @@ func TestQueryInlineArrayWithBooleans(t *testing.T) { Docs: map[int][]string{ 0: { `{ - "Name": "John", + "Name": "John", "LikedIndexes": [true, true, false, true] }`, }, @@ -114,8 +115,13 @@ func TestQueryInlineArrayWithNillableBooleans(t *testing.T) { }, Results: []map[string]any{ { - "Name": "John", - "IndexLikesDislikes": []Option[bool]{Some(true), Some(true), Some(false), None[bool]()}, + "Name": "John", + "IndexLikesDislikes": []immutable.Option[bool]{ + immutable.Some(true), + immutable.Some(true), + immutable.Some(false), + immutable.None[bool](), + }, }, }, } @@ -288,8 +294,14 @@ func TestQueryInlineArrayWithNillableInts(t *testing.T) { }, Results: []map[string]any{ { - "Name": "John", - "TestScores": []Option[int64]{Some[int64](-1), None[int64](), Some[int64](-1), Some[int64](2), Some[int64](0)}, + "Name": "John", + "TestScores": []immutable.Option[int64]{ + immutable.Some[int64](-1), + immutable.None[int64](), + immutable.Some[int64](-1), + immutable.Some[int64](2), + immutable.Some[int64](0), + }, }, }, } @@ -394,8 +406,13 @@ func TestQueryInlineArrayWithNillableFloats(t *testing.T) { }, Results: []map[string]any{ { - "Name": "John", - "PageRatings": []Option[float64]{Some(3.1425), None[float64](), Some(-0.00000000001), Some[float64](10)}, + "Name": "John", + "PageRatings": []immutable.Option[float64]{ + immutable.Some(3.1425), + immutable.None[float64](), + immutable.Some(-0.00000000001), + immutable.Some[float64](10), + }, }, }, } @@ -500,8 +517,14 @@ func TestQueryInlineArrayWithNillableString(t *testing.T) { }, Results: []map[string]any{ { - "Name": "John", - "PageHeaders": []Option[string]{Some(""), Some("the previous"), Some("the first"), Some("empty string"), None[string]()}, + "Name": "John", + "PageHeaders": []immutable.Option[string]{ + immutable.Some(""), + immutable.Some("the previous"), + immutable.Some("the first"), + immutable.Some("empty string"), + immutable.None[string](), + }, }, }, }