state

package
v1.202405300917.1 Latest Latest
Warning

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

Go to latest
Published: May 30, 2024 License: MIT Imports: 22 Imported by: 0

README

Principles

  • SafeStateAPI is a low-level API for State which implements the following principles:
    • used by extension engines
    • automatically converts package paths (extensions work with full paths)
    • Keys, Values, Key- and Value-Builders are represented with numbers, to be transferred between Host and Extension environments.

Design

flowchart TD
    exttinygo:::G
    exttinygotests:::G
    state:::G
    isafeapi:::G
    safestate:::G
    teststate:::G
    iextengine:::G
    application:::G
    wazero:::G
    processors:::G
    subgraph exttinygo
        internal.State["var SafeStateAPI"]:::S
        hostAPI["hostSafeStateApi"]:::S
        clientStateAPI["Client State API"]:::S
        subgraph exttinygotests
            NewTestAPI["NewTestAPI(...)"]:::S
        end
    end
    subgraph state
        IState:::S
        subgraph isafeapi
            IStateSafeAPI["IStateSafeAPI"]:::S
        end
        subgraph teststate
            ITestState["ITestState"]:::S
            ITestAPI["ITestAPI"]:::S
        end
        subgraph safestate
            safestate.Provide["safestate.Provide(...)"]:::S
        end
    end
    subgraph application["application package"]
        Test:::S
        Extension:::S
    end
    subgraph iextengine
        subgraph wazero
            IExtensionEngineWazero["IExtensionEngineWazero"]:::S
        end

        IExtensionEngine["IExtensionEngine"]:::S
    end
    subgraph processors
        Processor:::S
    end
    
    internal.State -.-> |by default initialized with| hostAPI
    internal.State -.-> |of type| IStateSafeAPI
    internal.State -.-> |used by| clientStateAPI

    NewTestAPI -.-> |1. constructs| ITestState
    NewTestAPI -.-> |2. calls| safestate.Provide
    NewTestAPI -.-> |3. sets| internal.State
    ITestState -.-> |implements| ITestAPI
    ITestState -.-> |implements| IState
    
    ITestAPI -.-> |used by| Test
    safestate.Provide -.-> |to provide| IStateSafeAPI

    hostAPI -.-> |calls host functions| IExtensionEngineWazero
    IExtensionEngine -.-> |can be| IExtensionEngineWazero

    Processor --> |has| IState
    IState -.-> |passed to| safestate.Provide
    IState -.-> |"passed to Invoke(...)"| IExtensionEngine
    IExtensionEngineWazero -.-> |calls| safestate.Provide
    Test -.-> |calls| Extension
    clientStateAPI -.-> |used by|Extension

classDef B fill:#FFFFB5,color:#333
classDef S fill:#B5FFFF,color:#333
classDef H fill:#C9E7B7,color:#333
classDef G fill:#ffffff15, stroke:#999, stroke-width:2px, stroke-dasharray: 5 5

Documentation

Index

Constants

View Source
const (
	S_GET       = 1
	S_GET_BATCH = 2
	S_READ      = 4
	S_INSERT    = 8
	S_UPDATE    = 16
)
View Source
const (
	Field_Url                           = "Url"
	Field_Method                        = "Method"
	Field_Header                        = "Header"
	Field_Offset                        = "Offset"
	Field_Error                         = "Error"
	Field_ErrStr                        = "ErrStr"
	Field_QNameFromParams               = "QNameFromParams"
	Field_ValidEvent                    = "ValidEvent"
	Field_QName                         = "QName"
	Field_ArgumentObject                = "ArgumentObject"
	Field_ArgumentUnloggedObject        = "ArgumentUnloggedObject"
	Field_Synced                        = "Synced"
	Field_Count                         = "Count"
	Field_ID                            = "ID"
	Field_From                          = "From"
	Field_To                            = "To"
	Field_CC                            = "CC"
	Field_BCC                           = "BCC"
	Field_Subject                       = "Subject"
	Field_Body                          = "Body"
	Field_PartitionID                   = "PartitionID"
	Field_WSID                          = "WSID"
	Field_HTTPClientTimeoutMilliseconds = "HTTPClientTimeoutMilliseconds"
	Field_Singleton                     = "Singleton"
	Field_Secret                        = "Secret"
	Field_RegisteredAt                  = "RegisteredAt"
	Field_DeviceID                      = "DeviceID"
	Field_SyncedAt                      = "SyncedAt"
	Field_WLogOffset                    = "WLogOffset"
	Field_Workspace                     = "Workspace"
	Field_Username                      = "Username"
	Field_Password                      = "Password"
	Field_Host                          = "Host"
	Field_Port                          = "Port"
	Field_StatusCode                    = "StatusCode"
	Field_Kind                          = "Kind"
	Field_ProfileWSID                   = "ProfileWSID"
	Field_CUDs                          = "CUDs"
	Field_IsNew                         = "IsNew"
	Field_Name                          = "Name"
	Field_Token                         = "Token"
	Field_ErrorMessage                  = "ErrorMessage"
)
View Source
const (
	ColOffset = "offs"
)

Variables

View Source
var (
	View           = appdef.NewQName(appdef.SysPackage, "View")
	Record         = appdef.NewQName(appdef.SysPackage, "Record")
	WLog           = appdef.NewQName(appdef.SysPackage, "WLog")
	Http           = appdef.NewQName(appdef.SysPackage, "Http")
	SendMail       = appdef.NewQName(appdef.SysPackage, "SendMail")
	AppSecret      = appdef.NewQName(appdef.SysPackage, "AppSecret")
	RequestSubject = appdef.NewQName(appdef.SysPackage, "RequestSubject")
	Result         = appdef.NewQName(appdef.SysPackage, "Result")
	Event          = appdef.NewQName(appdef.SysPackage, "Event")
	CommandContext = appdef.NewQName(appdef.SysPackage, "CommandContext")
	QueryContext   = appdef.NewQName(appdef.SysPackage, "QueryContext")
	Response       = appdef.NewQName(appdef.SysPackage, "Response")
)
View Source
var ErrExists = errors.New("exists")
View Source
var ErrGetNotSupportedByStorage = errors.New("get not supported by storage")
View Source
var ErrInsertNotSupportedByStorage = errors.New("insert not supported by storage")
View Source
var ErrIntentsLimitExceeded = errors.New("intents limit exceeded")
View Source
var ErrNotExists = errors.New("not exists")
View Source
var ErrNotFound = errors.New("not found")
View Source
var ErrNotSupported = errors.New("not supported")
View Source
var ErrReadNotSupportedByStorage = errors.New("read not supported by storage")
View Source
var ErrUnknownStorage = errors.New("unknown storage")
View Source
var ErrUpdateNotSupportedByStorage = errors.New("update not supported by storage")

Functions

func GetPrincipalTokenFromState

func GetPrincipalTokenFromState(st istructs.IState) (token string, err error)

Types

type ActualizerStateOptFunc

type ActualizerStateOptFunc func(opts *actualizerStateOpts)

func WithCustomHttpClient

func WithCustomHttpClient(client IHttpClient) ActualizerStateOptFunc

func WithEmailMessagesChan

func WithEmailMessagesChan(messages chan smtptest.Message) ActualizerStateOptFunc

type AppStructsFunc

type AppStructsFunc func() istructs.IAppStructs

type ApplyBatchItem

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

type ArgFunc

type ArgFunc func() istructs.IObject

type AsyncActualizerStateFactory

type AsyncActualizerStateFactory func(ctx context.Context, appStructsFunc AppStructsFunc, partitionIDFunc PartitionIDFunc, wsidFunc WSIDFunc, n10nFunc N10nFunc, secretReader isecrets.ISecretReader, eventFunc PLogEventFunc, intentsLimit, bundlesLimit int,
	opts ...ActualizerStateOptFunc) IBundledHostState

func ProvideAsyncActualizerStateFactory

func ProvideAsyncActualizerStateFactory() AsyncActualizerStateFactory

type CUDFunc

type CUDFunc func() istructs.ICUD

type CommandProcessorStateFactory

type CommandProcessorStateFactory func(ctx context.Context, appStructsFunc AppStructsFunc, partitionIDFunc PartitionIDFunc, wsidFunc WSIDFunc, secretReader isecrets.ISecretReader, cudFunc CUDFunc, principalPayloadFunc PrincipalsFunc, tokenFunc TokenFunc, intentsLimit int, cmdResultBuilderFunc ObjectBuilderFunc, argFunc ArgFunc, unloggedArgFunc UnloggedArgFunc, wlogOffsetFunc WLogOffsetFunc) IHostState

func ProvideCommandProcessorStateFactory

func ProvideCommandProcessorStateFactory() CommandProcessorStateFactory

type ExecQueryCallbackFunc

type ExecQueryCallbackFunc func() istructs.ExecQueryCallback

type GetBatchItem

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

type IBundledHostState

type IBundledHostState interface {
	IState

	// ApplyIntents validates and stores intents to bundles
	ApplyIntents() (readyToFlushBundle bool, err error)

	// FlushBundles flushes bundles to underlying storage and resets the bundles
	FlushBundles() (err error)
}

IBundledHostState buffers changes in "bundles" when ApplyIntents is called. Further Read- and *Exist operations see these changes.

type IHostState

type IHostState interface {
	IState

	// ValidateIntents validates intents
	ValidateIntents() (err error)
	// ApplyIntents applies intents to underlying storage
	ApplyIntents() (err error)
	// ClearIntents clears intents
	ClearIntents()
}

type IHttpClient

type IHttpClient interface {
	Request(timeout time.Duration, method, url string, body io.Reader, headers map[string]string) (statusCode int, resBody []byte, resHeaders map[string][]string, err error)
}

type IStateStorage

type IStateStorage interface {
	NewKeyBuilder(entity appdef.QName, existingKeyBuilder istructs.IStateKeyBuilder) (newKeyBuilder istructs.IStateKeyBuilder)
}

type IWithApplyBatch

type IWithApplyBatch interface {
	// Validate validates batch before store
	Validate(items []ApplyBatchItem) (err error)
	// ApplyBatch applies batch to storage
	ApplyBatch(items []ApplyBatchItem) (err error)
}

type IWithGet

type IWithGet interface {
	// Get reads item from storage
	// Nil value returned when item not found
	Get(key istructs.IStateKeyBuilder) (value istructs.IStateValue, err error)
}

type IWithGetBatch

type IWithGetBatch interface {
	// GetBatch reads items from storage
	GetBatch(items []GetBatchItem) (err error)
}

type IWithInsert

type IWithInsert interface {
	IWithApplyBatch

	// ProvideValueBuilder provides value builder. ExistingBuilder can be null
	ProvideValueBuilder(key istructs.IStateKeyBuilder, existingBuilder istructs.IStateValueBuilder) (istructs.IStateValueBuilder, error)
}

type IWithRead

type IWithRead interface {
	// Read reads items with callback. Can return many more than 1 item for the same get
	Read(key istructs.IStateKeyBuilder, callback istructs.ValueCallback) (err error)
}

type IWithUpdate

type IWithUpdate interface {
	IWithApplyBatch

	// ProvideValueBuilderForUpdate provides value builder to update the value. ExistingBuilder can be null
	ProvideValueBuilderForUpdate(key istructs.IStateKeyBuilder, existingValue istructs.IStateValue, existingBuilder istructs.IStateValueBuilder) (istructs.IStateValueBuilder, error)
}

type N10nFunc

type N10nFunc func(view appdef.QName, wsid istructs.WSID, offset istructs.Offset)

type ObjectBuilderFunc

type ObjectBuilderFunc func() istructs.IObjectBuilder

type PLogEventFunc

type PLogEventFunc func() istructs.IPLogEvent

type PartitionIDFunc

type PartitionIDFunc func() istructs.PartitionID

func SimplePartitionIDFunc

func SimplePartitionIDFunc(partitionID istructs.PartitionID) PartitionIDFunc

type PrincipalsFunc

type PrincipalsFunc func() []iauthnz.Principal

type QNameFunc

type QNameFunc func() appdef.QName

type QPStateOptFunc

type QPStateOptFunc func(opts *qpStateOpts)

func QPWithCustomHttpClient

func QPWithCustomHttpClient(client IHttpClient) QPStateOptFunc

type QueryProcessorStateFactory

type QueryProcessorStateFactory func(ctx context.Context, appStructsFunc AppStructsFunc, partitionIDFunc PartitionIDFunc, wsidFunc WSIDFunc, secretReader isecrets.ISecretReader, principalPayloadFunc PrincipalsFunc, tokenFunc TokenFunc, argFunc ArgFunc, resultBuilderFunc ObjectBuilderFunc, queryCallbackFunc ExecQueryCallbackFunc, opts ...QPStateOptFunc) IHostState

func ProvideQueryProcessorStateFactory

func ProvideQueryProcessorStateFactory() QueryProcessorStateFactory

type SyncActualizerStateFactory

type SyncActualizerStateFactory func(ctx context.Context, appStructsFunc AppStructsFunc, partitionIDFunc PartitionIDFunc, wsidFunc WSIDFunc, n10nFunc N10nFunc, secretReader isecrets.ISecretReader, eventFunc PLogEventFunc, intentsLimit int) IHostState

func ProvideSyncActualizerStateFactory

func ProvideSyncActualizerStateFactory() SyncActualizerStateFactory

type TokenFunc

type TokenFunc func() string

type UnloggedArgFunc

type UnloggedArgFunc func() istructs.IObject

type WLogOffsetFunc

type WLogOffsetFunc func() istructs.Offset

type WSIDFunc

type WSIDFunc func() istructs.WSID

func SimpleWSIDFunc

func SimpleWSIDFunc(wsid istructs.WSID) WSIDFunc

Directories

Path Synopsis
* Copyright (c) 2024-present unTill Software Development Group B. V. * @author Michael Saigachenko
* Copyright (c) 2024-present unTill Software Development Group B. V. * @author Michael Saigachenko
* Copyright (c) 2024-present unTill Software Development Group B. V. * @author Michael Saigachenko
* Copyright (c) 2024-present unTill Software Development Group B. V. * @author Michael Saigachenko

Jump to

Keyboard shortcuts

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