cptype

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2024 License: Apache-2.0 Imports: 6 Imported by: 265

Documentation

Index

Constants

View Source
const (
	// DefaultRenderingKey .
	DefaultRenderingKey = "__DefaultRendering__"

	// InParamsStateBindingKey .
	InParamsStateBindingKey = "__InParams__"
)

DefaultRenderingKey .

View Source
const (
	// DefaultComponentNamespace contains all common components.
	DefaultComponentNamespace = "__DefaultComponentNamespace__"
)

DefaultComponentNamespace .

View Source
const (
	// FieldImplForInject used to inject `Impl` field by framework.
	FieldImplForInject = "Impl"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CompBaseOperationRegister

type CompBaseOperationRegister interface {
	RegisterInitializeOp() (opFunc OperationFunc)
	RegisterRenderingOp() (opFunc OperationFunc)
}

CompBaseOperationRegister includes Initialize & Rendering Op.

type CompDecoder

type CompDecoder interface {
	DecodeData(srcRawPtr ComponentData, dstStdStructPtr interface{})
	DecodeState(srcRawPtr ComponentState, dstStdStructPtr interface{})
	DecodeInParams(srcRawPtr InParams, dstStdStructPtr interface{})
}

CompDecoder is a protocol-level interface, convert raw-cp-result to structured-struct. decode raw-ptr to std-struct-ptr.

type CompEncoder

type CompEncoder interface {
	EncodeData(srcStdStructPtr interface{}, dstRawPtr *ComponentData)
	EncodeState(srcStdStructPtr interface{}, dstRawPtr *ComponentState)
	EncodeInParams(srcStdStructPtr interface{}, dstRawPtr *InParams)
}

CompEncoder is a protocol-level interface, convert structured-struct to raw-cp-result. encode std-struct-ptr to raw-ptr.

type CompFrameworkSteper

type CompFrameworkSteper interface {
	Initialize(sdk *SDK)
	Finalize(sdk *SDK)
	SkipOp(sdk *SDK) bool
	Visible(sdk *SDK) bool
	BeforeHandleOp(sdk *SDK)
	AfterHandleOp(sdk *SDK)
}

CompFrameworkSteper represents all component steps played in framework.

type CompNonBaseOperationRegister

type CompNonBaseOperationRegister interface {
	CompStdOperationRegister
	CompNonStdOperationRegister
}

CompNonBaseOperationRegister includes a component's all non-base operations.

type CompNonStdOperationRegister

type CompNonStdOperationRegister interface {
	RegisterCompNonStdOps() (opFuncs map[OperationKey]OperationFunc)
}

CompNonStdOperationRegister register a component's all non-standard operations to standard cptype.OperationFunc, and then used by framework.

type CompOperationRegister

type CompOperationRegister interface {
	CompBaseOperationRegister
	CompNonBaseOperationRegister
}

CompOperationRegister includes a component's all operations.

type CompStdOperationRegister

type CompStdOperationRegister interface {
	RegisterCompStdOps() (opFuncs map[OperationKey]OperationFunc)
}

CompStdOperationRegister register a component's all standard operations to standard cptype.OperationFunc, and then used by framework.

type CompStdStructuredPtrCreator

type CompStdStructuredPtrCreator interface {
	StdStructuredPtrCreator() func() IStdStructuredPtr
}

CompStdStructuredPtrCreator return creator of StdStructuredPtr.

type Component

type Component struct {
	Version string `json:"version,omitempty" yaml:"version,omitempty"`
	// 组件类型
	Type string `json:"type,omitempty" yaml:"type,omitempty"`
	// 组件名字
	Name string `json:"name,omitempty" yaml:"name,omitempty"`
	// table 动态字段
	Props ComponentProps `json:"props,omitempty" yaml:"props,omitempty"`
	// 组件业务数据
	Data ComponentData `json:"data,omitempty" yaml:"data,omitempty"`
	// 前端组件状态
	State ComponentState `json:"state,omitempty" yaml:"state,omitempty"`
	// 组件相关操作(前端定义)
	Operations ComponentOperations `json:"operations,omitempty" yaml:"operations,omitempty"`
	// Component Options
	Options *ComponentOptions `json:"options,omitempty" yaml:"options,omitempty"`
}

Component defines a component.

type ComponentData

type ComponentData map[string]interface{}

ComponentData .

type ComponentEvent

type ComponentEvent struct {
	Component     string                 `json:"component"`
	Operation     OperationKey           `json:"operation"`
	OperationData map[string]interface{} `json:"operationData"`
}

ComponentEvent .

type ComponentOperations

type ComponentOperations map[string]interface{}

ComponentOperations .

type ComponentOptions

type ComponentOptions struct {
	Visible     bool `json:"visible,omitempty" yaml:"visible,omitempty"`
	AsyncAtInit bool `json:"asyncAtInit,omitempty" yaml:"asyncAtInit,omitempty"`

	// enable continueRender if not nil
	ContinueRender *ContinueRender `json:"continueRender,omitempty" yaml:"continueRender,omitempty"`

	// extra related
	FlatExtra            bool `json:"flatExtra,omitempty" yaml:"flatExtra,omitempty"`
	RemoveExtraAfterFlat bool `json:"removeExtraAfterFlat,omitempty" yaml:"removeExtraAfterFlat,omitempty"`

	// url query
	URLQuery string `json:"urlQuery,omitempty" yaml:"urlQuery,omitempty"`
}

ComponentOptions .

type ComponentProps

type ComponentProps map[string]interface{}

ComponentProps .

type ComponentProtocol

type ComponentProtocol struct {
	Version     string                   `json:"version" yaml:"version"`
	Scenario    string                   `json:"scenario" yaml:"scenario"`
	GlobalState *GlobalStateData         `json:"state" yaml:"state"`
	Hierarchy   Hierarchy                `json:"hierarchy" yaml:"hierarchy"`
	Components  map[string]*Component    `json:"components" yaml:"components"`
	Rendering   map[string][]RendingItem `json:"rendering" yaml:"rendering"`
	Options     *ProtocolOptions         `json:"options" yaml:"options"`
}

ComponentProtocol is protocol definition.

type ComponentProtocolDebugOptions

type ComponentProtocolDebugOptions struct {
	ComponentKey string `json:"componentKey"`
}

ComponentProtocolDebugOptions .

type ComponentProtocolParams

type ComponentProtocolParams interface{}

ComponentProtocolParams .

type ComponentProtocolRequest

type ComponentProtocolRequest struct {
	Scenario Scenario       `json:"scenario"`
	Event    ComponentEvent `json:"event"`
	InParams InParams       `json:"inParams"`
	// 初次请求为空,事件出发后,把包含状态的protocol传到后端
	Protocol *ComponentProtocol `json:"protocol"`

	// DebugOptions debug 选项
	DebugOptions *ComponentProtocolDebugOptions `json:"debugOptions,omitempty"`
}

ComponentProtocolRequest .

type ComponentState

type ComponentState map[string]interface{}

ComponentState .

type ContinueRender

type ContinueRender struct {
	OpKey string `json:"opKey,omitempty"`
}

ContinueRender .

type Extra

type Extra struct {
	Extra ExtraMap `json:"extra,omitempty"`
}

Extra is a magic fields, and will be flat if specified in protocol.

func (Extra) String

func (e Extra) String(key string) string

String .

func (Extra) Uint64

func (e Extra) Uint64(key string) uint64

Uint64 .

type ExtraMap

type ExtraMap map[string]interface{}

ExtraMap .

func (ExtraMap) Get

func (em ExtraMap) Get(key string) interface{}

Get .

func (ExtraMap) String

func (em ExtraMap) String(key string) string

String .

func (ExtraMap) Uint64

func (em ExtraMap) Uint64(key string) uint64

Uint64 .

type GlobalInnerCtxKey

type GlobalInnerCtxKey string

GlobalInnerCtxKey .

const (
	// GlobalInnerKeyCtxSDK .
	GlobalInnerKeyCtxSDK GlobalInnerCtxKey = "_sdk_"

	// GlobalInnerKeyUserIDs .
	GlobalInnerKeyUserIDs GlobalInnerCtxKey = "_userIDs_"

	// GlobalInnerKeyIdentity .
	GlobalInnerKeyIdentity GlobalInnerCtxKey = "_identity_"

	// GlobalInnerKeyError .
	GlobalInnerKeyError GlobalInnerCtxKey = "_error_"

	// GlobalInnerKeyStateTemp .
	GlobalInnerKeyStateTemp GlobalInnerCtxKey = "_state_temp_"
)

GlobalInnerKeyCtxSDK .

func (GlobalInnerCtxKey) String

func (k GlobalInnerCtxKey) String() string

String .

type GlobalStateData

type GlobalStateData map[string]interface{}

GlobalStateData .

type Hierarchy

type Hierarchy struct {
	Version string `json:"version" yaml:"version"`
	Root    string `json:"root" yaml:"root"`
	// structure的结构可能是list、map
	Structure map[string]interface{} `json:"structure" yaml:"structure"`
	// Parallel
	Parallel map[string][]string `json:"parallel,omitempty"`
}

Hierarchy represents components' hierarchy.

type IComponent

type IComponent interface {
	IDefaultComponent
	CompBaseOperationRegister
}

IComponent combines IDefaultComponent and BaseOperationRegister.

type IDefaultComponent

IDefaultComponent std component's default impl should implement this interface.

type IOperation

type IOperation interface {
	OpKey() OperationKey
}

IOperation .

type IStdStructuredPtr

type IStdStructuredPtr interface {
	DataPtr() interface{}
	StatePtr() interface{}
	InParamsPtr() interface{}
}

IStdStructuredPtr represents std structured pointer type.

type InParams

type InParams map[string]interface{}

InParams .

func (InParams) Int64

func (p InParams) Int64(key string) int64

Int64 .

func (InParams) String

func (p InParams) String(key string) string

String .

func (InParams) Uint64

func (p InParams) Uint64(key string) uint64

Uint64 .

type InvokeRenderWsEventPayload

type InvokeRenderWsEventPayload struct {
	RenderEvent ComponentEvent `json:"event,omitempty"`
}

InvokeRenderWsEventPayload .

type LegacyOperation

type LegacyOperation struct {
	Key         string `json:"key,omitempty"`
	Text        string `json:"text,omitempty"`
	Confirm     string `json:"confirm,omitempty"`
	Disabled    bool   `json:"disabled,omitempty"`
	DisabledTip string `json:"disabledTip,omitempty"`
	Reload      bool   `json:"reload,omitempty"`
}

LegacyOperation .

type OpClientData

type OpClientData struct {
	DataRef ExtraMap `json:"dataRef,omitempty"`
	ExtraMap
}

OpClientData .

type OpServerData

type OpServerData ExtraMap

OpServerData .

type Operation

type Operation struct {
	Text       string `json:"text,omitempty"`
	Tip        string `json:"tip,omitempty"`
	Confirm    string `json:"confirm,omitempty"`
	Disabled   bool   `json:"disabled,omitempty"`
	SkipRender bool   `json:"skipRender,omitempty"` // skipRender means this op is just a frontend op, won't invoke backend to render.
	Async      bool   `json:"async,omitempty"`

	// ServerData generated at server-side.
	ServerData *OpServerData `json:"serverData,omitempty"`
	// ClientData generated at client-side.
	ClientData *OpClientData `json:"clientData,omitempty"`
}

Operation .

type OperationFunc

type OperationFunc func(sdk *SDK) IStdStructuredPtr

OperationFunc return std structured response.

type OperationKey

type OperationKey string

OperationKey .

const (
	// 协议定义的操作
	// 用户通过URL初次访问
	InitializeOperation OperationKey = "__Initialize__"
	// 用于替换掉DefaultOperation,前端触发某组件,在协议Rending中定义了关联渲染组件,传递的事件是RendingOperation
	RenderingOperation OperationKey = "__Rendering__"

	SyncOperation        OperationKey = "__Sync__"
	AsyncAtInitOperation OperationKey = "__AsyncAtInit__"
)

InitializeOperation .

func (OperationKey) String

func (o OperationKey) String() string

String .

type ProtocolOptions

type ProtocolOptions struct {
	// SyncIntervalSecond can be float64, such as 10, 1, 0.5 .
	SyncIntervalSecond float64 `json:"syncIntervalSecond" yaml:"syncIntervalSecond"`

	// ParallelContinueRenders contains all component-level continue-render.
	ParallelContinueRenders map[string]ContinueRender `json:"parallelContinueRenders,omitempty" yaml:"parallelContinueRenders,omitempty"`

	// EnableWebSocket enable WebSocket for current scenario.
	EnableWebSocket bool `json:"enableWebSocket,omitempty" yaml:"enableWebSocket,omitempty"`

	// Only return rendering components if disabled
	ReturnAllComponents bool `json:"returnAllComponents" yaml:"returnAllComponents"`
}

ProtocolOptions .

type RendingItem

type RendingItem struct {
	Name  string         `json:"name" yaml:"name"`
	State []RendingState `json:"state" yaml:"state"`
}

RendingItem .

type RendingState

type RendingState struct {
	Name  string `json:"name" yaml:"name"`
	Value string `json:"value" yaml:"value"`
}

RendingState .

type SDK

type SDK struct {
	Ctx         context.Context
	Scenario    string
	Tran        i18n.Translator
	Identity    *pb.IdentityInfo
	InParams    InParams
	Lang        i18n.LanguageCodes
	GlobalState *GlobalStateData

	// ONLY FOR STD COMPONENT USE
	Event       ComponentEvent
	CompOpFuncs map[OperationKey]OperationFunc
	Comp        *Component

	// for parallel use, it's request level
	StdStructuredPtr IStdStructuredPtr
	// contains filtered or unexported fields
}

SDK .

func (*SDK) Clone

func (sdk *SDK) Clone() *SDK

Clone only return general-part of sdk to avoid concurrency issue.

func (*SDK) I18n

func (sdk *SDK) I18n(key string, args ...interface{}) string

I18n .

func (*SDK) MergeClonedGlobalState

func (sdk *SDK) MergeClonedGlobalState()

MergeClonedGlobalState merge cloned global state to origin unified global state.

func (*SDK) RegisterOperation

func (sdk *SDK) RegisterOperation(opKey OperationKey, opFunc OperationFunc)

RegisterOperation .

func (*SDK) SetUserIDs

func (sdk *SDK) SetUserIDs(userIDs []string)

SetUserIDs .

type Scenario

type Scenario struct {
	// 场景类型, 没有则为空
	ScenarioType string `json:"scenarioType" query:"scenarioType"`
	// 场景Key
	ScenarioKey string `json:"scenarioKey" query:"scenarioKey"`
}

Scenario .

type UIRenderWsEventPayload

type UIRenderWsEventPayload struct {
	Components map[string]*Component `json:"components,omitempty"`
}

UIRenderWsEventPayload .

type WebSocketEventType

type WebSocketEventType string

WebSocketEventType .

var (
	// WebSocketEventTypeInvokeRender means frontend need invoke operation render to backend.
	WebSocketEventTypeInvokeRender WebSocketEventType = "InvokeRender"
	// WebSocketEventTypeUIRender means just UI re-render, no need invoke backend.
	WebSocketEventTypeUIRender WebSocketEventType = "UIRender"
)

Jump to

Keyboard shortcuts

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