store

package
v0.0.0-...-8c2001a Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2024 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DefaultDataAssetsFolder   = "data_common"
	DefaultBprintFolder       = "bprints"
	DefaultTenantPublicFolder = "public"
	DefaultSystemIconsFolder  = "system_icons"
)
View Source
const (
	VendorSqlite   = "sqlite"
	VendorQL       = "ql"
	VendorPostgres = "postgres"
)

Variables

View Source
var (
	SlugExp        = regexp.MustCompile("^[a-z0-9-]*$")
	ReplaceSlugExp = regexp.MustCompile("[^a-z0-9]+")
	ReservedSlugs  = []string{"page", "limit", "cursor"} // fixme => copy all reserved words from from autoapi and other
)

Functions

func Slugify

func Slugify(s string) string

Types

type AgentOps

type AgentOps interface {
	AgentLinkNew(tenantId string, data *entities.AgentLink) error
	AgentLinkUpdate(tenantId, pid, aid string, id int64, data map[string]any) error
	AgentLinkGet(tenantId, pid, aid string, id int64) (*entities.AgentLink, error)
	AgentLinkDel(tenantId, pid, aid string, id int64) error
	AgentLinkList(tenantId, pid, aid string) ([]*entities.AgentLink, error)
	AgentLinkListReverse(tenantId, pid, aid string) ([]*entities.AgentLink, error)

	AgentLinkListByPlug(tenantId, pid string) ([]*entities.AgentLink, error)

	AgentExtensionNew(tenantId string, data *entities.AgentExtension) error
	AgentExtensionUpdate(tenantId, pid, aid string, id int64, data map[string]any) error
	AgentExtensionGet(tenantId, pid, aid string, id int64) (*entities.AgentExtension, error)
	AgentExtensionDel(tenantId, pid, aid string, id int64) error
	AgentExtensionList(tenantId, pid, aid string) ([]*entities.AgentExtension, error)

	AgentExtensionListByPlug(tenantId, pid string) ([]*entities.AgentExtension, error)

	AgentResourceNew(tenantId string, data *entities.AgentResource) error
	AgentResourceUpdate(tenantId, pid, aid, slug string, data map[string]any) error
	AgentResourceGet(tenantId, pid, aid, slug string) (*entities.AgentResource, error)
	AgentResourceDel(tenantId, pid, aid, slug string) error
	AgentResourceList(tenantId, pid, aid string) ([]*entities.AgentResource, error)

	ListResourcePairs(tenantId string, pid, aid string) ([]entities.ResourcePair, error)
}

type AuthZ

type AuthZ interface {
	CheckScope(scope string) bool
	CheckAction(user, action string) (bool, error)
}

type BlobInfo

type BlobInfo struct {
	Name         string `json:"name,omitempty"`
	IsDir        bool   `json:"is_dir,omitempty"`
	Size         int    `json:"size,omitempty"`
	LastModified string `json:"last_modified,omitempty"`
}

type BprintOps

type BprintOps interface {
	BprintNew(tenantId string, et *entities.BPrint) error
	BprintUpdate(tenantId, id string, data map[string]any) error
	BprintGet(tenantId, id string) (*entities.BPrint, error)
	BprintDel(tenantId, id string) error
	BprintList(tenantId, group string) ([]*entities.BPrint, error)
}

type Builder

type Builder func(opts BuilderOptions) (Store, error)

type BuilderOptions

type BuilderOptions struct {
	Config     *config.StoreSource
	LogBuilder func() zerolog.Logger
}

type CabinetHub

type CabinetHub interface {
	Start(mb xplane.MsgBus) error
	Default(tenant string) CabinetSourced
	ListSources(tenant string) ([]string, error)
	GetSource(source, tenant string) CabinetSourced
	DefaultName(tenantId string) string
}

type CabinetSource

type CabinetSource interface {
	InitilizeTenent(tenent string, folders []string) error
	AddFolder(ctx context.Context, tenant, folder string) error
	AddBlob(ctx context.Context, tenant, folder string, file string, contents []byte) error
	AddBlobStreaming(ctx context.Context, tenant, folder string, file string, contents io.ReadCloser) error
	ListRoot(ctx context.Context, tenant string) ([]string, error)
	ListFolderBlobs(ctx context.Context, tenant, folder string) ([]*BlobInfo, error)
	GetBlob(ctx context.Context, tenant, folder string, file string) ([]byte, error)
	DeleteBlob(ctx context.Context, tenant, folder string, file string) error
}

type CabinetSourced

type CabinetSourced interface {
	AddFolder(Context context.Context, folder string) error
	AddBlob(Context context.Context, folder, file string, contents []byte) error // fixme putblob
	ListRoot(Context context.Context) ([]string, error)
	ListFolder(Context context.Context, folder string) ([]*BlobInfo, error)
	GetBlob(Context context.Context, folder, file string) ([]byte, error)
	DeleteBlob(Context context.Context, folder, file string) error
	Name() string
}

type CoreHub

type CoreHub interface {
	CoreDB

	GetAuthZ(tenantId, group string) AuthZ

	Inject(app xtypes.App)
}

type Error

type Error struct {
	Inner   string
	LogId   string
	CtxData any
}

func (*Error) Error

func (e *Error) Error() string

type EventQuery

type EventQuery struct {
	TenantId string
	Etype    string
	Last     int64
}

type PkvQuery

type PkvQuery struct {
	KeyPrefix string   `json:"key_prefix,omitempty"`
	LoadMeta  bool     `json:"load_meta,omitempty"`
	Tag1s     []string `json:"tag1s,omitempty"`
	Tag2s     []string `json:"tag2s,omitempty"`
	Tag3s     []string `json:"tag3s,omitempty"`
	PageCount uint     `json:"page_count,omitempty"`
	Page      uint     `json:"page,omitempty"`
	KeyCursor string   `json:"key_cursor,omitempty"`
	NoValue   bool     `json:"no_value,omitempty"`
}

type PlugOps

type PlugOps interface {
	PlugNew(tenantId string, pg *entities.Plug) error
	PlugUpdate(tenantId string, id string, data map[string]any) error
	PlugGet(tenantId, pid string) (*entities.Plug, error)
	PlugDel(tenantId, pid string) error
	PlugList(tenantId string, cond map[string]any) ([]*entities.Plug, error)

	PlugListByBprint(tenantId, bprint string) ([]*entities.Plug, error)

	AgentNew(tenantId string, data *entities.Agent) error
	AgentUpdate(tenantId, pid, id string, data map[string]any) error
	AgentGet(tenantId, pid, id string) (*entities.Agent, error)
	AgentDel(tenantId, pid, agentId string) error
	AgentList(tenantId, pid string) ([]*entities.Agent, error)

	ResourceNew(tenantId string, obj *entities.Resource) error
	ResourceUpdate(tenantId string, id string, data map[string]any) error
	ResourceGet(tenantId, rid string) (*entities.Resource, error)
	ResourceDel(tenantId, rid string) error
	ResourceList(tenantId string, cond map[string]any) ([]*entities.Resource, error)
	ResourcesMulti(tenantId string, rids ...string) ([]*entities.Resource, error)
	ResourcesByTarget(tenantId string, target string) ([]*entities.Resource, error)

	GetFlowMap(tenantId string) (*flowmap.Data, error)
}

type PlugStateKV

type PlugStateKV interface {
	SetBatch(txid uint32, tenantId, plugId string, opts *SetBatchOptions) error
	Set(txid uint32, tenantId, plugId, key, value string, opts *SetOptions) error
	Update(txid uint32, tenantId, plugId, key, value string, opts *UpdateOptions) error
	Get(txid uint32, tenantId, plugId, key string) (*entities.PlugKV, error)
	Query(txid uint32, tenantId, plugId string, query *PkvQuery) ([]*entities.PlugKV, error)
	Del(txid uint32, tenantId, plugId, key string) error
	DelBatch(txid uint32, tenantId, plugId string, keys []string) error

	NewTxn() (uint32, error)
	RollBack(txid uint32) error
	Commit(txid uint32) error
}

type RepoOps

type RepoOps interface {
	RepoNew(tenantId string, pg *entities.Repo) error
	RepoUpdate(tenantId string, id int64, data map[string]any) error
	RepoGet(tenantId string, id int64) (*entities.Repo, error)
	RepoDel(tenantId string, id int64) error
	RepoList(tenantId string) ([]*entities.Repo, error)
}

type SetBatchOptions

type SetBatchOptions struct {
	ClearBefore bool             `json:"clear_before,omitempty"`
	Records     []map[string]any `json:"records,omitempty"`
}

type SetOptions

type SetOptions struct {
	Tag1 string `json:"tag1,omitempty"`
	Tag2 string `json:"tag2,omitempty"`
	Tag3 string `json:"tag3,omitempty"`
	TTL  int    `json:"ttl,omitempty"`
}

type StateHub

type StateHub interface {
	OnTargetAppChange(tenantId string, id int64, data any)
	OnTargetHookChange(tenantId string, id int64, data any)
	OnResourceChange(tenantId, id string, data any)
	OnUserGroupChange(tenantId, id string, data any)

	OnDataGroupChange(tenantId, gid string, data any)
	OnDataTableChange(tenantId, gid, tid string, data any)
	OnDataColumnChange(tenantId, gid, tid, cid string, data any)

	OnTenantChange(id string, data any)
	OnDomainChange(tenantId string, id int64, data any)
}

type Store

type Store interface {
	Supports(StoreType) bool
	CoreDB() CoreDB
	DynDB() dyndb.DynDB
	StateDB() PlugStateKV
	CabinetSource() CabinetSource
	Name() string
}

type StoreType

type StoreType string
const (
	TypeCoreDB    StoreType = "core_db"
	TypeDynDB     StoreType = "dyn_db"
	TypeStateDB   StoreType = "state_db"
	TypeSyncDB    StoreType = "sync_db"
	TypeBlobStore StoreType = "blob_store"
)

type SyncDB

type SyncDB interface {
	RepoOps
	BprintOps
	PlugOps
	AgentOps
}

type SystemOps

type SystemOps interface {
	AddSystemEvent(data *entities.SystemEvent) error
	RemoveSystemEvent(id int64) error
	ListSystemEvent(last int64) ([]*entities.SystemEvent, error)
	QuerySystemEvent(query EventQuery) ([]*entities.SystemEvent, error)

	AddSystemKV(tenantId string, data *entities.SystemKV) error
	UpdateSystemKV(tenantId, key, ktype string, data map[string]any) error
	GetSystemKV(tenantId, key, ktype string) (*entities.SystemKV, error)
	RemoveSystemKV(tenantId, key, ktype string) error
	ListSystemKV(tenantId, ktype, prefix string, last int64) ([]*entities.SystemKV, error)
}

type TargetOps

type TargetOps interface {
	AddTargetHook(data *entities.TargetHook) (int64, error)
	UpdateTargetHook(tenantId, ttype string, id int64, data map[string]any) error
	ListTargetHook(tenantId string, cond map[string]any) ([]*entities.TargetHook, error)
	ListTargetHookByType(tenantId, ttype, target string) ([]*entities.TargetHook, error)
	ListTargetHookByPlug(tenantId, plug string) ([]*entities.TargetHook, error)
	GetTargetHook(tenantId, ttype string, id int64) (*entities.TargetHook, error)
	RemoveTargetHook(tenantId, ttype string, id int64) error

	AddTargetApp(data *entities.TargetApp) (int64, error)
	UpdateTargetApp(tenantId, ttype string, id int64, data map[string]any) error
	ListTargetApp(tenantId string, cond map[string]any) ([]*entities.TargetApp, error)
	ListTargetAppByType(tenantId, ttype, target string) ([]*entities.TargetApp, error)
	ListTargetAppByPlug(tenantId, plug string) ([]*entities.TargetApp, error)
	GetTargetApp(tenantId, ttype string, id int64) (*entities.TargetApp, error)
	RemoveTargetApp(tenantId, ttype string, id int64) error

	ListTargetAppByUgroup(tenantId, ugroup string) ([]*entities.TargetApp, error)
}

type TenantOps

type TenantOps interface {
	AddTenant(tenant *entities.Tenant) error
	UpdateTenant(slug string, data map[string]any) error
	GetTenant(tenant string) (*entities.Tenant, error)
	RemoveTenant(slug string) error
	ListTenant() ([]*entities.Tenant, error)

	AddDomain(domain *entities.TenantDomain) (int64, error)
	UpdateDomain(tenantId string, id int64, data map[string]any) error
	GetDomain(tenantId string, id int64) (*entities.TenantDomain, error)
	GetDomainByName(tenantId string, name string) (*entities.TenantDomain, error)

	RemoveDomain(tenantId string, id int64) error
	ListDomain(tenantId string) ([]*entities.TenantDomain, error)
}

type UpdateOptions

type UpdateOptions struct {
	ForceVer    bool   `json:"force_ver,omitempty"`
	WithVerison bool   `json:"with_version,omitempty"`
	Version     int    `json:"version,omitempty"`
	SetTag1     bool   `json:"set_tag1,omitempty"`
	SetTag2     bool   `json:"set_tag2,omitempty"`
	SetTag3     bool   `json:"set_tag3,omitempty"`
	Tag1        string `json:"tag1,omitempty"`
	Tag2        string `json:"tag2,omitempty"`
	Tag3        string `json:"tag3,omitempty"`
	SetTTL      bool   `json:"set_ttl,omitempty"`
	TTL         int    `json:"ttl,omitempty"`
}

type UserGroupExtra

type UserGroupExtra interface {
	AddUserGroupAuth(data *entities.UserGroupAuth) error
	UpdateUserGroupAuth(tenantId string, gslug string, id int64, data map[string]any) error
	ListUserGroupAuth(tenantId string, gslug string) ([]*entities.UserGroupAuth, error)
	GetUserGroupAuth(tenantId string, gslug string, id int64) (*entities.UserGroupAuth, error)
	RemoveUserGroupAuth(tenantId, gslug string, id int64) error

	AddUserGroupData(data *entities.UserGroupData) error
	UpdateUserGroupData(tenantId string, gslug string, id int64, data map[string]any) error
	ListUserGroupData(tenantId string, gslug string) ([]*entities.UserGroupData, error)
	GetUserGroupData(tenantId string, gslug string, id int64) (*entities.UserGroupData, error)
	RemoveUserGroupData(tenantId, gslug string, id int64) error
}

type UserMessageOps

type UserMessageOps interface {
	AddUserMessage(msg *entities.UserMessage) (int64, error)
	UserMessageSetRead(tenantId, user string, id int64) error
	RemoveUserMessage(tenantId string, userid string, id int64) error
	ListUserMessages(tenantId string, data *entities.UserMessageReq) ([]*entities.UserMessage, error)

	ReadUserMessages(tenantId, userId string, id []int64) error
	DeleteUserMessages(tenantId, userId string, id []int64) error
}

type UserOps

type UserOps interface {
	AddUserGroup(ug *entities.UserGroup) error
	GetUserGroup(tenantId string, slug string) (*entities.UserGroup, error)
	ListUserGroups(tenantId string) ([]*entities.UserGroup, error)
	UpdateUserGroup(tenantId, slug string, data map[string]any) error
	RemoveUserGroup(tenantId string, ugslug string) error

	AddUser(user *entities.User, data *entities.UserData) error
	UpdateUser(tenantId, user string, data map[string]any) error
	RemoveUser(tenantId string, userid string) error
	GetUserByID(tenantId string, userid string) (*entities.User, error)
	GetUserByEmail(tenantId string, email string) (*entities.User, error)
	ListUsers(tenantId string) ([]*entities.User, error)
	ListUsersByGroup(tenantId, group string) ([]*entities.User, error)
	ListUsersMulti(tenantId string, users ...string) ([]*entities.User, error)

	GetUserData(tenantId string, slug string) (*entities.UserData, error)
	UpdateUserData(tenantId, slug string, data map[string]any) error

	AddUserDevice(tenantId string, user string, data *entities.UserDevice) error
	UpdateUserDevice(tenantId string, user string, id int64, data map[string]any) error
	GetUserDevice(tenantId string, user string, id int64) (*entities.UserDevice, error)
	ListUserDevice(tenantId string, user string) ([]*entities.UserDevice, error)
	RemoveUserDevice(tenantId string, user string, id int64) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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