Documentation
¶
Index ¶
- Variables
- func DSKeyToOrm(k iface.Key) orm.Key
- func OrmKeyToDS(k orm.Key) iface.Key
- func SetSearchIndex(index SearchIndex)
- type AccessTokens
- func (at *AccessTokens) AddToken(name string, permissions bit.Mask) string
- func (at *AccessTokens) ClearTokens()
- func (at *AccessTokens) CompareToken(tok1, tok2 *accesstoken.AccessToken) error
- func (at *AccessTokens) GetToken(accessToken string) (*accesstoken.AccessToken, error)
- func (at *AccessTokens) GetTokenByName(name string) (*accesstoken.AccessToken, error)
- func (at *AccessTokens) GetWithAccessToken(accessToken string) (*accesstoken.AccessToken, error)
- func (at *AccessTokens) Init(e Entity)
- func (at *AccessTokens) MustGetTokenByName(name string) *accesstoken.AccessToken
- func (at *AccessTokens) RemoveToken(name string)
- type AfterCreate
- type AfterDelete
- type AfterUpdate
- type BaseModel
- func (m *BaseModel) Clone() Entity
- func (m *BaseModel) CloneFromJSON() Entity
- func (m *BaseModel) Context() context.Context
- func (m *BaseModel) Create() error
- func (m *BaseModel) Created() bool
- func (m *BaseModel) Datastore() *datastore.Datastore
- func (m *BaseModel) Delete() error
- func (m BaseModel) DeleteDocument() error
- func (m *BaseModel) Exists() (bool, error)
- func (m *BaseModel) Get(key datastore.Key) error
- func (m *BaseModel) GetById(id string) error
- func (m *BaseModel) GetOrCreate(filterStr string, value interface{}) error
- func (m *BaseModel) GetOrUpdate(filterStr string, value interface{}) error
- func (m *BaseModel) Id() string
- func (m *BaseModel) IdExists(id string) (datastore.Key, bool, error)
- func (m *BaseModel) Init(db *datastore.Datastore, entity Kind)
- func (m *BaseModel) JSON() []byte
- func (m *BaseModel) JSONString() string
- func (m *BaseModel) Key() (key datastore.Key)
- func (m *BaseModel) KeyExists(key datastore.Key) (bool, error)
- func (m BaseModel) Kind() string
- func (m *BaseModel) Loaded() bool
- func (m *BaseModel) MustCreate()
- func (m *BaseModel) MustDelete()
- func (m *BaseModel) MustGet(key datastore.Key)
- func (m *BaseModel) MustGetById(id string)
- func (m *BaseModel) MustPut()
- func (m *BaseModel) MustSetKey(key interface{})
- func (m *BaseModel) MustUpdate()
- func (m *BaseModel) Namespace() string
- func (m *BaseModel) NewKey() datastore.Key
- func (m *BaseModel) Put() error
- func (m BaseModel) PutDocument() error
- func (m *BaseModel) Query() *ModelQuery
- func (m *BaseModel) RunInTransaction(fn func() error, opts *datastore.TransactionOptions) error
- func (m *BaseModel) SetContext(ctx context.Context)
- func (m *BaseModel) SetEntity(entity interface{})
- func (m *BaseModel) SetKey(key interface{}) (err error)
- func (m *BaseModel) SetNamespace(namespace string)
- func (m *BaseModel) Slice() interface{}
- func (m *BaseModel) Update() error
- func (m *BaseModel) Zero() Entity
- type BeforeCreate
- type BeforeDelete
- type BeforeUpdate
- type DatastoreAdapter
- func (a *DatastoreAdapter) AllocateIDs(kind string, parent orm.Key, n int) ([]orm.Key, error)
- func (a *DatastoreAdapter) Close() error
- func (a *DatastoreAdapter) Datastore() *datastore.Datastore
- func (a *DatastoreAdapter) Delete(ctx context.Context, k orm.Key) error
- func (a *DatastoreAdapter) Get(ctx context.Context, k orm.Key, dst interface{}) error
- func (a *DatastoreAdapter) NewIncompleteKey(kind string, parent orm.Key) orm.Key
- func (a *DatastoreAdapter) NewKey(kind, stringID string, intID int64, parent orm.Key) orm.Key
- func (a *DatastoreAdapter) Put(ctx context.Context, k orm.Key, src interface{}) (orm.Key, error)
- func (a *DatastoreAdapter) Query(kind string) orm.Query
- func (a *DatastoreAdapter) RunInTransaction(ctx context.Context, fn func(tx orm.DB) error) error
- func (a *DatastoreAdapter) String() string
- type Defaults
- type Document
- type DocumentSaveLoad
- type Entity
- type ErrFacetMismatch
- type ErrFieldMismatch
- type ErrorMessage
- type JsonResponse
- type Kind
- type Model
- func (b *Model[T]) Clone() Entity
- func (b *Model[T]) CloneFromJSON() Entity
- func (b *Model[T]) Context() context.Context
- func (b *Model[T]) Created() bool
- func (b *Model[T]) Datastore() *datastore.Datastore
- func (b *Model[T]) DeleteDocument() error
- func (b *Model[T]) Exists() (bool, error)
- func (b *Model[T]) Get(key datastore.Key) error
- func (b *Model[T]) GetCreatedAt() time.Time
- func (b *Model[T]) GetOrCreate(filterStr string, value interface{}) error
- func (b *Model[T]) GetOrUpdate(filterStr string, value interface{}) error
- func (b *Model[T]) GetUpdatedAt() time.Time
- func (b *Model[T]) IdExists(id string) (datastore.Key, bool, error)
- func (b *Model[T]) Init(db *datastore.Datastore)
- func (b *Model[T]) JSON() []byte
- func (b *Model[T]) JSONString() string
- func (b *Model[T]) Key() datastore.Key
- func (b *Model[T]) KeyExists(key datastore.Key) (bool, error)
- func (b *Model[T]) Loaded() bool
- func (b *Model[T]) MustGet(key datastore.Key)
- func (b *Model[T]) MustGetById(id string)
- func (b *Model[T]) MustPut()
- func (b *Model[T]) MustSetKey(key interface{})
- func (b *Model[T]) Namespace() string
- func (b *Model[T]) NewKey() datastore.Key
- func (b *Model[T]) PutDocument() error
- func (b *Model[T]) Query() *ModelQuery
- func (b *Model[T]) RunInTransaction(fn func() error, opts *datastore.TransactionOptions) error
- func (b *Model[T]) SetContext(ctx context.Context)
- func (b *Model[T]) SetKey(key interface{}) error
- func (b *Model[T]) SetNamespace(namespace string)
- func (b *Model[T]) Slice() interface{}
- func (b *Model[T]) Zero() Entity
- type ModelQuery
- func (q *ModelQuery) All() datastore.Query
- func (q *ModelQuery) Ancestor(key datastore.Key) *ModelQuery
- func (q *ModelQuery) ById(id string) (bool, error)
- func (q *ModelQuery) ByKey(key interface{}) (bool, error)
- func (q *ModelQuery) Filter(filterStr string, value interface{}) *ModelQuery
- func (q *ModelQuery) Get() (bool, error)
- func (q *ModelQuery) GetKey() (bool, error)
- func (q *ModelQuery) IdExists(id string) (datastore.Key, bool, error)
- func (q *ModelQuery) KeyExists(key datastore.Key) (bool, error)
- func (q *ModelQuery) Limit(limit int) *ModelQuery
- func (q *ModelQuery) MustGet()
- func (q *ModelQuery) MustGetKey()
- func (q *ModelQuery) Offset(offset int) *ModelQuery
- func (q *ModelQuery) Order(order string) *ModelQuery
- type Salesforce
- func (so *Salesforce) ExternalId() string
- func (so *Salesforce) LastSync() time.Time
- func (so *Salesforce) SalesforceId() string
- func (so *Salesforce) SalesforceId2() string
- func (so *Salesforce) SetExternalId(id string)
- func (so *Salesforce) SetLastSync()
- func (so *Salesforce) SetSalesforceId(id string)
- func (so *Salesforce) SetSalesforceId2(id string)
- type SearchDocumentMetadata
- type SearchFacet
- type SearchField
- type SearchIndex
- type Searchable
Constants ¶
This section is empty.
Variables ¶
var DefaultIndex = "everything"
var ErrorExpiredToken = errors.New("This token is expired")
Error for expired jti's
var TokenNotFound = errors.New("Token not found")
var TokenNotFoundByName = errors.New("Token not found by name")
Functions ¶
func DSKeyToOrm ¶ added in v1.35.0
DSKeyToOrm is the exported version for use in bridge code.
func OrmKeyToDS ¶ added in v1.35.0
OrmKeyToDS is the exported version for use in bridge code.
func SetSearchIndex ¶
func SetSearchIndex(index SearchIndex)
SetSearchIndex sets the search index implementation to use
Types ¶
type AccessTokens ¶
type AccessTokens struct {
// Entity is a struct with a Entity mixin
Entity Entity `json:"-" datastore:"-"`
// JWT secret (persisted for token verification)
SecretKey []byte `json:"secretKey,omitempty"`
// UseTokenId as JWT "jti" param, randomly generate upon generating a new key to expire all existing keys
Tokens []accesstoken.AccessToken `json:"tokens,omitempty"`
}
AccessTokens is a mixin for securing objects with an AccessTokens
func (*AccessTokens) AddToken ¶
func (at *AccessTokens) AddToken(name string, permissions bit.Mask) string
func (*AccessTokens) ClearTokens ¶
func (at *AccessTokens) ClearTokens()
func (*AccessTokens) CompareToken ¶
func (at *AccessTokens) CompareToken(tok1, tok2 *accesstoken.AccessToken) error
func (*AccessTokens) GetToken ¶
func (at *AccessTokens) GetToken(accessToken string) (*accesstoken.AccessToken, error)
func (*AccessTokens) GetTokenByName ¶
func (at *AccessTokens) GetTokenByName(name string) (*accesstoken.AccessToken, error)
func (*AccessTokens) GetWithAccessToken ¶
func (at *AccessTokens) GetWithAccessToken(accessToken string) (*accesstoken.AccessToken, error)
func (*AccessTokens) Init ¶
func (at *AccessTokens) Init(e Entity)
func (*AccessTokens) MustGetTokenByName ¶
func (at *AccessTokens) MustGetTokenByName(name string) *accesstoken.AccessToken
func (*AccessTokens) RemoveToken ¶
func (at *AccessTokens) RemoveToken(name string)
type AfterCreate ¶
type AfterCreate interface {
AfterCreate() error
}
type AfterDelete ¶
type AfterDelete interface {
AfterDelete() error
}
type AfterUpdate ¶
type BaseModel ¶ added in v1.35.0
type BaseModel struct {
Db *datastore.Datastore `json:"-" datastore:"-"`
Entity Kind `json:"-" datastore:"-"`
Parent datastore.Key `json:"-" datastore:"-"`
Mock bool `json:"-" datastore:"-"`
// Set by our mixin
Id_ string `json:"id,omitempty"`
Loaded_ bool `json:"-" datastore:"-"`
CreatedAt time.Time `json:"createdAt,omitempty"`
UpdatedAt time.Time `json:"updatedAt,omitempty"`
Deleted bool `json:"deleted,omitempty"`
// Flag used to specify that we're using a string key for this kind
UseStringKey bool `json:"-" datastore:"-"`
// contains filtered or unexported fields
}
Model is a mixin which adds Datastore/Validation/Serialization methods to any Kind that it has been embedded in.
func (*BaseModel) CloneFromJSON ¶ added in v1.35.0
Create a clone of currenty entity using only JSON-serializable data
func (BaseModel) DeleteDocument ¶ added in v1.35.0
func (*BaseModel) GetById ¶ added in v1.35.0
Helper that will retrieve entity by id (which may be an encoded key/slug/sku)
func (*BaseModel) GetOrCreate ¶ added in v1.35.0
Get entity from datastore or create new one
func (*BaseModel) GetOrUpdate ¶ added in v1.35.0
Get entity from datastore or create new one
func (*BaseModel) JSONString ¶ added in v1.35.0
func (*BaseModel) MustGetById ¶ added in v1.35.0
Get by id or panic
func (*BaseModel) MustSetKey ¶ added in v1.35.0
func (m *BaseModel) MustSetKey(key interface{})
Set key or panic
func (BaseModel) PutDocument ¶ added in v1.35.0
func (*BaseModel) Query ¶ added in v1.35.0
func (m *BaseModel) Query() *ModelQuery
Return a query for this entity kind
func (*BaseModel) RunInTransaction ¶ added in v1.35.0
func (m *BaseModel) RunInTransaction(fn func() error, opts *datastore.TransactionOptions) error
Run in transaction using model's current context
func (*BaseModel) SetContext ¶ added in v1.35.0
Set context.Context
func (*BaseModel) SetEntity ¶ added in v1.35.0
func (m *BaseModel) SetEntity(entity interface{})
Set entity on mixin so it can be referenced later
func (*BaseModel) SetNamespace ¶ added in v1.35.0
Set context.Context namespace
func (*BaseModel) Slice ¶ added in v1.35.0
func (m *BaseModel) Slice() interface{}
Create a slice of entity type suitable for use with datastore.GetAll, etc.
type BeforeCreate ¶
type BeforeCreate interface {
BeforeCreate() error
}
type BeforeDelete ¶
type BeforeDelete interface {
BeforeDelete() error
}
type BeforeUpdate ¶
These last two interfaces are largely ignored -- we use helper below to have nicely typed update hooks in models.
type DatastoreAdapter ¶ added in v1.35.0
type DatastoreAdapter struct {
// contains filtered or unexported fields
}
DatastoreAdapter wraps *datastore.Datastore to implement orm.DB.
func NewDatastoreAdapter ¶ added in v1.35.0
func NewDatastoreAdapter(ds *datastore.Datastore) *DatastoreAdapter
NewDatastoreAdapter creates a new adapter wrapping a commerce datastore.
func (*DatastoreAdapter) AllocateIDs ¶ added in v1.35.0
func (*DatastoreAdapter) Close ¶ added in v1.35.0
func (a *DatastoreAdapter) Close() error
func (*DatastoreAdapter) Datastore ¶ added in v1.35.0
func (a *DatastoreAdapter) Datastore() *datastore.Datastore
Datastore returns the underlying commerce datastore.
func (*DatastoreAdapter) NewIncompleteKey ¶ added in v1.35.0
func (*DatastoreAdapter) Query ¶ added in v1.35.0
func (a *DatastoreAdapter) Query(kind string) orm.Query
func (*DatastoreAdapter) RunInTransaction ¶ added in v1.35.0
func (*DatastoreAdapter) String ¶ added in v1.35.0
func (a *DatastoreAdapter) String() string
String representation for debugging.
type DocumentSaveLoad ¶
type DocumentSaveLoad struct {
// Dummy field for gob, see: https://github.com/golang/go/issues/5819
Dummy string `json:"-" datastore:"-"`
// contains filtered or unexported fields
}
func (*DocumentSaveLoad) GetDocument ¶
func (s *DocumentSaveLoad) GetDocument() reflect.Value
func (*DocumentSaveLoad) Load ¶
func (s *DocumentSaveLoad) Load(fields []SearchField, meta *SearchDocumentMetadata) error
func (DocumentSaveLoad) Save ¶
func (s DocumentSaveLoad) Save() ([]SearchField, *SearchDocumentMetadata, error)
func (*DocumentSaveLoad) SetDocument ¶
func (s *DocumentSaveLoad) SetDocument(doc interface{})
type Entity ¶
type Entity interface {
// TODO: Should not be embedded in Entity I don't think
Kind
// By convention where model is wired to entity
Init(db *datastore.Datastore)
// Get, Set context/namespace
Context() context.Context
SetContext(ctx context.Context)
SetNamespace(namespace string)
Namespace() string
// Get, Set keys
Key() (key datastore.Key)
SetKey(key interface{}) error
NewKey() datastore.Key
Id() string
// Various existential helpers
Exists() (bool, error)
IdExists(id string) (datastore.Key, bool, error)
KeyExists(key datastore.Key) (bool, error)
// Get, Put, Delete + Create, Update
Get(key datastore.Key) error
GetById(id string) error
Put() error
Create() error
Update() error
Delete() error
// Must variants
MustSetKey(key interface{})
MustCreate()
MustDelete()
MustGet(key datastore.Key)
MustGetById(id string)
MustPut()
MustUpdate()
// Document
PutDocument() error
DeleteDocument() error
// Get or Create, Update helpers
GetOrCreate(filterStr string, value interface{}) error
GetOrUpdate(filterStr string, value interface{}) error
// Datastore
Datastore() *datastore.Datastore
RunInTransaction(fn func() error, opts *datastore.TransactionOptions) error
// Query
Query() *ModelQuery
// Various helpers
Zero() Entity
Clone() Entity
CloneFromJSON() Entity
Slice() interface{}
JSON() []byte
JSONString() string
}
A specific datastore entity, with methods inherited from this mixin
type ErrFacetMismatch ¶
ErrFacetMismatch is returned when a facet is to be loaded into a different type than the one it was stored from, or when a field is missing or unexported in the destination struct. StructType is the type of the struct pointed to by the destination argument passed to Iterator.Next.
func (*ErrFacetMismatch) Error ¶
func (e *ErrFacetMismatch) Error() string
type ErrFieldMismatch ¶
ErrFieldMismatch is returned when a field is to be loaded into a different than the one it was stored from, or when a field is missing or unexported in the destination struct.
func (*ErrFieldMismatch) Error ¶
func (e *ErrFieldMismatch) Error() string
type ErrorMessage ¶
type JsonResponse ¶
type JsonResponse struct {
Meta struct {
RetrievedAt string
ExecutionTime int64
CallsUsed int64
}
Errors []ErrorMessage
}
type Kind ¶
type Kind interface {
Kind() string
}
A datastore kind that is compatible with the Model mixin
type Model ¶
type Model[T any] struct { orm.Model[T] Parent datastore.Key `json:"-" datastore:"-"` Mock bool `json:"-" datastore:"-"` // contains filtered or unexported fields }
Model[T] embeds orm.Model[T] and provides mixin.Entity compatibility. The orm.Model[T] must be the first field so self() pointer arithmetic works.
func (*Model[T]) CloneFromJSON ¶
func (*Model[T]) DeleteDocument ¶
func (*Model[T]) GetCreatedAt ¶ added in v1.35.0
func (*Model[T]) GetOrCreate ¶
func (*Model[T]) GetOrUpdate ¶
func (*Model[T]) GetUpdatedAt ¶ added in v1.35.0
func (*Model[T]) Init ¶
Init wires the bridge to a commerce datastore. Creates an ORM adapter, initializes the orm.Model, and applies defaults.
func (*Model[T]) JSONString ¶
func (*Model[T]) Loaded ¶
loaded_ prevents duplicate deserialization in Load() methods. Matches mixin.BaseModel.Loaded() semantics: returns true if already loaded, otherwise marks as loaded and returns false.
func (*Model[T]) MustGetById ¶
func (*Model[T]) MustSetKey ¶
func (b *Model[T]) MustSetKey(key interface{})
func (*Model[T]) PutDocument ¶
func (*Model[T]) Query ¶
func (b *Model[T]) Query() *ModelQuery
Query returns a mixin.ModelQuery for this entity.
func (*Model[T]) RunInTransaction ¶
func (b *Model[T]) RunInTransaction(fn func() error, opts *datastore.TransactionOptions) error
func (*Model[T]) SetContext ¶
func (*Model[T]) SetNamespace ¶
type ModelQuery ¶
type ModelQuery struct {
// contains filtered or unexported fields
}
This is a simple Query helper for individual models. Allows you to query for a single entity or key only as a convenience on an individual model.
func (*ModelQuery) All ¶
func (q *ModelQuery) All() datastore.Query
func (*ModelQuery) Ancestor ¶
func (q *ModelQuery) Ancestor(key datastore.Key) *ModelQuery
func (*ModelQuery) Filter ¶
func (q *ModelQuery) Filter(filterStr string, value interface{}) *ModelQuery
func (*ModelQuery) KeyExists ¶
func (q *ModelQuery) KeyExists(key datastore.Key) (bool, error)
Check if key exists
func (*ModelQuery) Limit ¶
func (q *ModelQuery) Limit(limit int) *ModelQuery
func (*ModelQuery) MustGet ¶
func (q *ModelQuery) MustGet()
func (*ModelQuery) MustGetKey ¶
func (q *ModelQuery) MustGetKey()
func (*ModelQuery) Offset ¶
func (q *ModelQuery) Offset(offset int) *ModelQuery
func (*ModelQuery) Order ¶
func (q *ModelQuery) Order(order string) *ModelQuery
type Salesforce ¶
type Salesforce struct {
PrimarySalesforceId_ string `json:"-"`
SecondarySalesforceId_ string `json:"-"`
ExternalId_ string `json:"-"`
LastSync_ time.Time `json:"-"`
}
func (*Salesforce) ExternalId ¶
func (so *Salesforce) ExternalId() string
func (*Salesforce) LastSync ¶
func (so *Salesforce) LastSync() time.Time
func (*Salesforce) SalesforceId ¶
func (so *Salesforce) SalesforceId() string
func (*Salesforce) SalesforceId2 ¶
func (so *Salesforce) SalesforceId2() string
func (*Salesforce) SetExternalId ¶
func (so *Salesforce) SetExternalId(id string)
func (*Salesforce) SetLastSync ¶
func (so *Salesforce) SetLastSync()
func (*Salesforce) SetSalesforceId ¶
func (so *Salesforce) SetSalesforceId(id string)
func (*Salesforce) SetSalesforceId2 ¶
func (so *Salesforce) SetSalesforceId2(id string)
type SearchDocumentMetadata ¶
type SearchDocumentMetadata struct {
Facets []SearchFacet
}
SearchDocumentMetadata holds metadata for a search document
type SearchFacet ¶
type SearchFacet struct {
Name string
Value interface{}
}
SearchFacet represents a facet in a search document
type SearchField ¶
type SearchField struct {
Name string
Value interface{}
}
SearchField represents a field in a search document
type SearchIndex ¶
type SearchIndex interface {
Put(ctx context.Context, id string, doc interface{}) error
Delete(ctx context.Context, id string) error
}
SearchIndex provides an interface for search operations This allows pluggable search backends (Elasticsearch, Meilisearch, etc.)
func GetSearchIndex ¶
func GetSearchIndex() SearchIndex
GetSearchIndex returns the current search index, or nil if not set
type Searchable ¶
type Searchable interface {
Document() Document
}
Searchable is implemented by models that can be indexed for search