model

package
v1.8.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2024 License: MIT Imports: 26 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AllowedStages = []string{
	"$addFields",
	"$group",
	"$project",
	"$search",
	"$set",
	"$unset",
	"$unwind",
}
View Source
var AuthMutex = sync.RWMutex{}

Functions

func GetIDAsString added in v1.2.44

func GetIDAsString(idToConvert interface{}) string

func ParseFilter added in v1.2.39

func ParseFilter(filter string) *wst.Filter

Types

type ACL

type ACL struct {
	AccessType    string `json:"accessType"`
	PrincipalType string `json:"principalType"`
	PrincipalId   string `json:"principalId"`
	Permission    string `json:"permission"`
	Property      string `json:"property"`
}

type ArgHttp added in v1.2.97

type ArgHttp struct {
	Source string
}

type BearerRole added in v1.2.44

type BearerRole struct {
	Name string
}

type BearerToken added in v1.2.44

type BearerToken struct {
	User   *BearerUser
	Roles  []BearerRole
	Raw    string
	Claims jwt.MapClaims
}

func CreateBearer added in v1.8.0

func CreateBearer(subjectId interface{}, createdAtSeconds float64, ttlSeconds float64, roles []string) *BearerToken

type BearerUser added in v1.2.44

type BearerUser struct {
	Id     interface{}
	Data   interface{}
	System bool
}

type CacheConfig added in v1.2.94

type CacheConfig struct {
	Datasource    string     `json:"datasource"`
	Ttl           int        `json:"ttl"`
	Keys          [][]string `json:"keys"`
	ExcludeFields []string   `json:"excludeFields"`
}

type CasbinConfig added in v1.2.44

type CasbinConfig struct {
	RequestDefinition  string   `json:"requestDefinition"`
	PolicyDefinition   string   `json:"policyDefinition"`
	RoleDefinition     string   `json:"roleDefinition"`
	PolicyEffect       string   `json:"policyEffect"`
	MatchersDefinition string   `json:"matchersDefinition"`
	Policies           []string `json:"policies"`
}

type ChannelCursor added in v1.6.0

type ChannelCursor struct {
	Err          error
	UsedPipeline *wst.A
	// contains filtered or unexported fields
}

func (*ChannelCursor) All added in v1.6.0

func (cursor *ChannelCursor) All() (result InstanceA, err error)

func (*ChannelCursor) Close added in v1.6.0

func (cursor *ChannelCursor) Close() error

func (*ChannelCursor) Error added in v1.6.0

func (cursor *ChannelCursor) Error(err error)

func (*ChannelCursor) Next added in v1.6.0

func (cursor *ChannelCursor) Next() (result *Instance, err error)

type Chunk added in v1.5.47

type Chunk struct {
	// contains filtered or unexported fields
}

type ChunkGenerator added in v1.5.47

type ChunkGenerator interface {
	ContentType() string

	GenerateNextChunk() error
	NextChunk() (Chunk, error)

	SetDebug(bool)
	Reader(ctx *EventContext) io.Reader
}

func NewCursorChunkGenerator added in v1.6.0

func NewCursorChunkGenerator(loadedModel *Model, cursor Cursor) ChunkGenerator

func NewInstanceAChunkGenerator added in v1.5.47

func NewInstanceAChunkGenerator(loadedModel *Model, input InstanceA, contentType string) ChunkGenerator

type ChunkGeneratorReader added in v1.5.47

type ChunkGeneratorReader struct {
	// contains filtered or unexported fields
}

func (*ChunkGeneratorReader) Read added in v1.5.47

func (reader *ChunkGeneratorReader) Read(p []byte) (n int, err error)

type Config

type Config struct {
	Name       string                `json:"name"`
	Plural     string                `json:"plural"`
	Base       string                `json:"base"`
	Public     bool                  `json:"public"`
	Properties map[string]Property   `json:"properties"`
	Relations  *map[string]*Relation `json:"relations"`
	Hidden     []string              `json:"hidden"`
	Protected  []string              `json:"protected"`
	Casbin     CasbinConfig          `json:"casbin"`
	Cache      CacheConfig           `json:"cache"`
	Mongo      MongoConfig           `json:"mongo"`
}

type Cursor added in v1.6.0

type Cursor interface {
	Next() (result *Instance, err error)
	All() (result InstanceA, err error)
	Close() error
}

func NewChannelCursor added in v1.6.0

func NewChannelCursor(channel chan *Instance) Cursor

type DataSourceConfig

type DataSourceConfig struct {
	Name      string `json:"name"`
	Connector string `json:"connector"`
	Host      string `json:"host"`
	Port      int    `json:"port"`
	Database  string `json:"database"`
	Username  string `json:"username"`
	Password  string `json:"password"`
}

type EphemeralData added in v1.2.50

type EphemeralData wst.M

type ErrorCursor added in v1.6.3

type ErrorCursor struct {
	// contains filtered or unexported fields
}

func (*ErrorCursor) All added in v1.6.3

func (cursor *ErrorCursor) All() (result InstanceA, err error)

func (*ErrorCursor) Close added in v1.6.3

func (cursor *ErrorCursor) Close() error

func (*ErrorCursor) Error added in v1.6.3

func (cursor *ErrorCursor) Error() error

func (*ErrorCursor) Next added in v1.6.3

func (cursor *ErrorCursor) Next() (result *Instance, err error)

type EventContext

type EventContext struct {
	Bearer                 *BearerToken
	BaseContext            *EventContext
	Remote                 *RemoteMethodOptions
	Filter                 *wst.Filter
	Data                   *wst.M
	Query                  *wst.M
	Instance               *Instance
	Ctx                    *fiber.Ctx
	Ephemeral              *EphemeralData
	IsNewInstance          bool
	Result                 interface{}
	Model                  *Model
	ModelID                interface{}
	StatusCode             int
	DisableTypeConversions bool
	SkipFieldProtection    bool
	OperationName          wst.OperationName
	Handled                bool
}

func FindBaseContext added in v1.7.2

func FindBaseContext(currentContext *EventContext) *EventContext

func (*EventContext) GetBearer added in v1.2.44

func (eventContext *EventContext) GetBearer(loadedModel *Model) (error, *BearerToken)

func (*EventContext) UpdateEphemeral added in v1.2.50

func (eventContext *EventContext) UpdateEphemeral(newData *wst.M)

type FixedLengthCursor added in v1.6.14

type FixedLengthCursor struct {
	// contains filtered or unexported fields
}

func (*FixedLengthCursor) All added in v1.6.14

func (cursor *FixedLengthCursor) All() (result InstanceA, err error)

func (*FixedLengthCursor) Close added in v1.6.14

func (cursor *FixedLengthCursor) Close() error

func (*FixedLengthCursor) Next added in v1.6.14

func (cursor *FixedLengthCursor) Next() (result *Instance, err error)

type Instance added in v1.2.71

type Instance struct {
	Model *Model
	Id    interface{}
	// contains filtered or unexported fields
}

func (*Instance) Get added in v1.2.71

func (modelInstance *Instance) Get(relationName string) interface{}

func (*Instance) GetA added in v1.3.9

func (modelInstance *Instance) GetA(path string) *wst.A

func (*Instance) GetBoolean added in v1.3.7

func (modelInstance *Instance) GetBoolean(path string, defaultValue bool) bool

func (*Instance) GetFloat64 added in v1.2.94

func (modelInstance *Instance) GetFloat64(path string) float64

func (*Instance) GetInt added in v1.2.97

func (modelInstance *Instance) GetInt(path string) int64

func (*Instance) GetM added in v1.2.98

func (modelInstance *Instance) GetM(path string) *wst.M

func (*Instance) GetMany added in v1.2.71

func (modelInstance *Instance) GetMany(relationName string) InstanceA

func (*Instance) GetObjectId added in v1.2.97

func (modelInstance *Instance) GetObjectId(path string) (result primitive.ObjectID)

func (*Instance) GetOne added in v1.2.71

func (modelInstance *Instance) GetOne(relationName string) *Instance

func (*Instance) GetString added in v1.2.94

func (modelInstance *Instance) GetString(path string) string

func (*Instance) HideProperties added in v1.2.71

func (modelInstance *Instance) HideProperties()

func (*Instance) MarshalBSON added in v1.5.47

func (modelInstance *Instance) MarshalBSON() (out []byte, err error)

func (*Instance) Reload added in v1.2.71

func (modelInstance *Instance) Reload(eventContext *EventContext) error

func (*Instance) ToJSON added in v1.2.71

func (modelInstance *Instance) ToJSON() wst.M

func (*Instance) Transform added in v1.2.71

func (modelInstance *Instance) Transform(out interface{}) (err error)

func (*Instance) UncheckedTransform added in v1.2.71

func (modelInstance *Instance) UncheckedTransform(out interface{}) interface{}

func (*Instance) UpdateAttributes added in v1.2.71

func (modelInstance *Instance) UpdateAttributes(data interface{}, baseContext *EventContext) (*Instance, error)

type InstanceA added in v1.2.76

type InstanceA []Instance

func (InstanceA) ToJSON added in v1.2.76

func (instances InstanceA) ToJSON() []wst.M

type InstanceAChunkGenerator added in v1.5.47

type InstanceAChunkGenerator struct {
	Debug bool
	// contains filtered or unexported fields
}

func (*InstanceAChunkGenerator) ContentType added in v1.5.47

func (chunkGenerator *InstanceAChunkGenerator) ContentType() string

func (*InstanceAChunkGenerator) GenerateNextChunk added in v1.5.47

func (chunkGenerator *InstanceAChunkGenerator) GenerateNextChunk() (err error)

func (*InstanceAChunkGenerator) NextChunk added in v1.5.47

func (chunkGenerator *InstanceAChunkGenerator) NextChunk() (chunk Chunk, err error)

func (*InstanceAChunkGenerator) Reader added in v1.5.47

func (chunkGenerator *InstanceAChunkGenerator) Reader(eventContext *EventContext) io.Reader

func (*InstanceAChunkGenerator) SetDebug added in v1.6.0

func (chunkGenerator *InstanceAChunkGenerator) SetDebug(debug bool)

type Model

type Model struct {
	Name             string                 `json:"name"`
	CollectionName   string                 `json:"-"`
	Config           *Config                `json:"-"`
	Datasource       *datasource.Datasource `json:"-"`
	Router           *fiber.Router          `json:"-"`
	App              *wst.IApp              `json:"-"`
	BaseUrl          string                 `json:"-"`
	CasbinModel      *casbinmodel.Model
	CasbinAdapter    **fileadapter.Adapter
	Enforcer         *casbin.Enforcer
	DisabledHandlers map[string]bool
	NilInstance      *Instance
	// contains filtered or unexported fields
}

func New

func New(config *Config, modelRegistry *map[string]*Model) *Model

func (*Model) Build

func (loadedModel *Model) Build(data wst.M, currentContext *EventContext) (Instance, error)

func (*Model) Count added in v1.5.40

func (loadedModel *Model) Count(filterMap *wst.Filter, currentContext *EventContext) (int64, error)

func (*Model) Create

func (loadedModel *Model) Create(data interface{}, currentContext *EventContext) (*Instance, error)

func (*Model) DeleteById

func (loadedModel *Model) DeleteById(id interface{}, currentContext *EventContext) (datasource.DeleteResult, error)

func (*Model) DeleteMany added in v1.6.13

func (loadedModel *Model) DeleteMany(where *wst.Where, currentContext *EventContext) (result datasource.DeleteResult, err error)

func (*Model) EnforceEx added in v1.2.73

func (loadedModel *Model) EnforceEx(token *BearerToken, objId string, action string, eventContext *EventContext) (error, bool)

func (*Model) ExtractLookupsFromFilter added in v1.2.18

func (loadedModel *Model) ExtractLookupsFromFilter(filterMap *wst.Filter, disableTypeConversions bool) (*wst.A, error)

func (*Model) FindById

func (loadedModel *Model) FindById(id interface{}, filterMap *wst.Filter, baseContext *EventContext) (*Instance, error)

func (*Model) FindMany

func (loadedModel *Model) FindMany(filterMap *wst.Filter, currentContext *EventContext) Cursor

func (*Model) FindOne

func (loadedModel *Model) FindOne(filterMap *wst.Filter, baseContext *EventContext) (*Instance, error)

func (*Model) GetHandler

func (loadedModel *Model) GetHandler(event string) func(eventContext *EventContext) error

func (*Model) GetModelRegistry added in v1.2.73

func (loadedModel *Model) GetModelRegistry() *map[string]*Model

func (*Model) HandleRemoteMethod added in v1.2.44

func (loadedModel *Model) HandleRemoteMethod(name string, eventContext *EventContext) error

func (*Model) Initialize added in v1.2.94

func (loadedModel *Model) Initialize()

func (*Model) Observe

func (loadedModel *Model) Observe(operation string, handler func(eventContext *EventContext) error)

func (*Model) On

func (loadedModel *Model) On(event string, handler func(eventContext *EventContext) error)

func (*Model) RemoteMethod

func (loadedModel *Model) RemoteMethod(handler func(context *EventContext) error, options RemoteMethodOptions) fiber.Router

type MongoConfig added in v1.3.10

type MongoConfig struct {
	//Database string `json:"database"`
	Collection string `json:"collection"`
}

type OperationItem added in v1.2.44

type OperationItem struct {
	Handler func(context *EventContext) error
	Options RemoteMethodOptions
}

type Property

type Property struct {
	Type     interface{} `json:"type"`
	Required bool        `json:"required"`
	Default  interface{} `json:"default"`
}

type RegistryEntry

type RegistryEntry struct {
	Name  string
	Model *Model
}

type Relation

type Relation struct {
	Type       string  `json:"type"`
	Model      string  `json:"model"`
	PrimaryKey *string `json:"primaryKey"`
	ForeignKey *string `json:"foreignKey"`
	Options    struct {
		//Inverse bool `json:"inverse"`
		SkipAuth bool `json:"skipAuth"`
	} `json:"options"`
}

type RemoteMethodOptions

type RemoteMethodOptions struct {
	Name        string
	Description string
	Accepts     RemoteMethodOptionsHttpArgs
	Http        RemoteMethodOptionsHttp
}

type RemoteMethodOptionsHttp

type RemoteMethodOptionsHttp struct {
	Path string
	Verb string
}

type RemoteMethodOptionsHttpArg added in v1.2.97

type RemoteMethodOptionsHttpArg struct {
	Arg         string
	Type        string
	Description string
	Http        ArgHttp
	Required    bool
}

type RemoteMethodOptionsHttpArgs added in v1.2.97

type RemoteMethodOptionsHttpArgs []RemoteMethodOptionsHttpArg

type SimplifiedConfig added in v1.2.79

type SimplifiedConfig struct {
	Datasource string `json:"dataSource"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL