rename scope to selector (#257)

* rename scope to selector

per design changes, source is being renamed to selector
for better readability and clarity.
This commit is contained in:
Keepers 2022-06-30 09:50:24 -06:00 committed by GitHub
parent ce52cc5f41
commit ae778df5ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 48 additions and 48 deletions

View File

@ -1,35 +1,35 @@
package source
package selectors
import (
"strconv"
)
// ExchangeSource provides an api for scoping
// Exchange provides an api for scoping
// data in the Exchange service.
type ExchangeSource struct {
Source
type Exchange struct {
Selector
}
// ToExchange transforms the generic source into an ExchangeSource.
// Errors if the service defined by the source is not ServiceExchange.
func (s Source) ToExchange() (*ExchangeSource, error) {
// ToExchange transforms the generic selector into an Exchange.
// Errors if the service defined by the selector is not ServiceExchange.
func (s Selector) ToExchange() (*Exchange, error) {
if s.service != ServiceExchange {
return nil, badCastErr(ServiceExchange, s.service)
}
src := ExchangeSource{s}
src := Exchange{s}
return &src, nil
}
// NewExchange produces a new Source with the service set to ServiceExchange.
func NewExchange(tenantID string) *ExchangeSource {
src := ExchangeSource{
newSource(tenantID, ServiceExchange),
// NewExchange produces a new Selector with the service set to ServiceExchange.
func NewExchange(tenantID string) *Exchange {
src := Exchange{
newSelector(tenantID, ServiceExchange),
}
return &src
}
// Scopes retrieves the list of exchangeScopes in the source.
func (s *ExchangeSource) Scopes() []exchangeScope {
// Scopes retrieves the list of exchangeScopes in the selector.
func (s *Exchange) Scopes() []exchangeScope {
scopes := []exchangeScope{}
for _, v := range s.scopes {
scopes = append(scopes, exchangeScope(v))
@ -38,31 +38,31 @@ func (s *ExchangeSource) Scopes() []exchangeScope {
}
// the following are called by the client to specify the constraints
// each call appends one or more scopes to the source.
// each call appends one or more scopes to the selector.
// Users selects the specified users. All of their data is included.
func (s *ExchangeSource) Users(us ...string) {
func (s *Exchange) Users(us ...string) {
// todo
}
// Contacts selects the specified contacts owned by the user.
func (s *ExchangeSource) Contacts(u string, vs ...string) {
func (s *Exchange) Contacts(u string, vs ...string) {
// todo
}
// Events selects the specified events owned by the user.
func (s *ExchangeSource) Events(u string, vs ...string) {
func (s *Exchange) Events(u string, vs ...string) {
// todo
}
// MailFolders selects the specified mail folders owned by the user.
func (s *ExchangeSource) MailFolders(u string, vs ...string) {
func (s *Exchange) MailFolders(u string, vs ...string) {
// todo
}
// MailMessages selects the specified mail messages within the given folder,
// owned by the user.
func (s *ExchangeSource) MailMessages(u, f string, vs ...string) {
func (s *Exchange) MailMessages(u, f string, vs ...string) {
// todo
}

View File

@ -1,4 +1,4 @@
package source_test
package selectors_test
import (
"testing"
@ -6,7 +6,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"github.com/alcionai/corso/pkg/source"
"github.com/alcionai/corso/pkg/selectors"
)
type ExchangeSourceSuite struct {
@ -19,8 +19,8 @@ func TestExchangeSourceSuite(t *testing.T) {
func (suite *ExchangeSourceSuite) TestNewExchangeSource() {
t := suite.T()
es := source.NewExchange("tid")
es := selectors.NewExchange("tid")
assert.Equal(t, es.TenantID, "tid")
assert.Equal(t, es.Service(), source.ServiceExchange)
assert.Equal(t, es.Service(), selectors.ServiceExchange)
assert.NotZero(t, es.Scopes())
}

View File

@ -1,4 +1,4 @@
package source
package selectors
import (
"strconv"
@ -14,7 +14,7 @@ const (
ServiceExchange // Exchange
)
var ErrorBadSourceCast = errors.New("wrong source service type")
var ErrorBadSelectorCast = errors.New("wrong selector service type")
const (
scopeKeyGranularity = "granularity"
@ -27,30 +27,30 @@ const (
All = "*"
)
// The core source. Has no api for setting or retrieving data.
// Is only used to pass along more specific source instances.
type Source struct {
// The core selector. Has no api for setting or retrieving data.
// Is only used to pass along more specific selector instances.
type Selector struct {
TenantID string // The tenant making the request.
service service // The service scope of the data. Exchange, Teams, Sharepoint, etc.
scopes []map[string]string // A slice of scopes. Expected to get cast to fooScope within each service handler.
}
// helper for specific source instance constructors.
func newSource(tenantID string, s service) Source {
return Source{
// helper for specific selector instance constructors.
func newSelector(tenantID string, s service) Selector {
return Selector{
TenantID: tenantID,
service: s,
scopes: []map[string]string{},
}
}
// Service return the service enum for the source.
func (s Source) Service() service {
// Service return the service enum for the selector.
func (s Selector) Service() service {
return s.service
}
func badCastErr(cast, is service) error {
return errors.Wrapf(ErrorBadSourceCast, "%s service is not %s", cast, is)
return errors.Wrapf(ErrorBadSelectorCast, "%s service is not %s", cast, is)
}
type scopeGranularity int
@ -68,8 +68,8 @@ func (g scopeGranularity) String() string {
return strconv.Itoa(int(g))
}
func granularityOf(source map[string]string) scopeGranularity {
return scopeGranularity(getIota(source, scopeKeyGranularity))
func granularityOf(selector map[string]string) scopeGranularity {
return scopeGranularity(getIota(selector, scopeKeyGranularity))
}
// retrieves the iota, stored as a string, and transforms it to

View File

@ -1,4 +1,4 @@
package source
package selectors
import (
"fmt"
@ -8,37 +8,37 @@ import (
"github.com/stretchr/testify/suite"
)
type SourceSuite struct {
type SelectorSuite struct {
suite.Suite
}
func TestSourceSuite(t *testing.T) {
suite.Run(t, new(SourceSuite))
func TestSelectorSuite(t *testing.T) {
suite.Run(t, new(SelectorSuite))
}
func (suite *SourceSuite) TestNewSource() {
func (suite *SelectorSuite) TestNewSelector() {
t := suite.T()
s := newSource("tid", ServiceUnknown)
s := newSelector("tid", ServiceUnknown)
assert.NotNil(t, s)
assert.Equal(t, s.TenantID, "tid")
assert.Equal(t, s.service, ServiceUnknown)
assert.NotNil(t, s.scopes)
}
func (suite *SourceSuite) TestSource_Service() {
func (suite *SelectorSuite) TestSelector_Service() {
table := []service{
ServiceUnknown,
ServiceExchange,
}
for _, test := range table {
suite.T().Run(fmt.Sprintf("testing %d", test), func(t *testing.T) {
s := newSource("tid", test)
s := newSelector("tid", test)
assert.Equal(t, s.Service(), test)
})
}
}
func (suite *SourceSuite) TestGetIota() {
func (suite *SelectorSuite) TestGetIota() {
table := []struct {
name string
val string
@ -59,7 +59,7 @@ func (suite *SourceSuite) TestGetIota() {
}
}
func (suite *SourceSuite) TestBadCastErr() {
func (suite *SelectorSuite) TestBadCastErr() {
err := badCastErr(ServiceUnknown, ServiceExchange)
assert.Error(suite.T(), err)
}

View File

@ -1,6 +1,6 @@
// Code generated by "stringer -type=service -linecomment"; DO NOT EDIT.
package source
package selectors
import "strconv"