chasm

package
v1.27.0-rc.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package chasm is a generated GoMock package.

Package chasm is a generated GoMock package.

Package chasm is a generated GoMock package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewEntity

func NewEntity[C Component, I any, O any](
	ctx context.Context,
	key EntityKey,
	newFn func(MutableContext, I) (C, O, error),
	input I,
	opts ...TransitionOption,
) (O, []byte, error)

func PollComponent

func PollComponent[C Component, R []byte | ComponentRef, I any, O any, T any](
	ctx context.Context,
	r R,
	predicateFn func(C, Context, I) (T, bool, error),
	operationFn func(C, MutableContext, I, T) (O, error),
	input I,
	opts ...TransitionOption,
) (O, []byte, error)

func ReadComponent

func ReadComponent[C Component, R []byte | ComponentRef, I any, O any](
	ctx context.Context,
	r R,
	readFn func(C, Context, I) (O, error),
	input I,
	opts ...TransitionOption,
) (O, error)

func UpdateComponent

func UpdateComponent[C Component, R []byte | ComponentRef, I any, O any](
	ctx context.Context,
	r R,
	updateFn func(C, MutableContext, I) (O, error),
	input I,
	opts ...TransitionOption,
) (O, []byte, error)

TODO:

  • consider merge with ReadComponent
  • consider remove ComponentRef from the return value and allow components to get the ref in the transition function. There are some caveats there, check the comment of the NewRef method in MutableContext.

func UpdateWithNewEntity

func UpdateWithNewEntity[C Component, I any, O1 any, O2 any](
	ctx context.Context,
	key EntityKey,
	newFn func(MutableContext, I) (C, O1, error),
	updateFn func(C, MutableContext, I) (O2, error),
	input I,
	opts ...TransitionOption,
) (O1, O2, []byte, error)

Types

type BusinessIDConflictPolicy

type BusinessIDConflictPolicy int
const (
	BusinessIDConflictPolicyFail BusinessIDConflictPolicy = iota
	BusinessIDConflictPolicyTermiateExisting
	BusinessIDConflictPolicyUseExisting
)

type BusinessIDReusePolicy

type BusinessIDReusePolicy int
const (
	BusinessIDReusePolicyAllowDuplicate BusinessIDReusePolicy = iota
	BusinessIDReusePolicyRejectDuplicate
)

type Collection

type Collection[T any] map[string]*Field[T]

type Component

type Component interface {
	LifecycleState() LifecycleState
	// contains filtered or unexported methods
}

type ComponentFieldOption

type ComponentFieldOption func(*componentFieldOptions)

func ComponentFieldDetached

func ComponentFieldDetached() ComponentFieldOption

type ComponentRef

type ComponentRef struct {
	EntityKey
	// contains filtered or unexported fields
}

func DeserializeComponentRef

func DeserializeComponentRef(data []byte) (ComponentRef, error)

func NewComponentRef

func NewComponentRef(
	entityKey EntityKey,
	rootComponentType string,
) ComponentRef

In V1, if you don't have a ref, then you can only interact with the top level entity.

func (*ComponentRef) Serialize

func (r *ComponentRef) Serialize() []byte

type Context

type Context interface {

	// NOTE: component created in the current transaction won't have a ref
	// this is a Ref to the component state at the start of the transition
	Ref(Component) (ComponentRef, bool)
	Now(Component) time.Time
	// contains filtered or unexported methods
}

type EntityKey

type EntityKey struct {
	NamespaceID string
	BusinessID  string
	EntityID    string
}

type Field

type Field[T any] struct {
	Internal fieldInternal
}

This struct needs to be create via reflection but reflection can't set prviate fields...

func NewComponentField

func NewComponentField[C Component](
	ctx MutableContext,
	c C,
	options ...ComponentFieldOption,
) *Field[C]

func NewComponentPointerField

func NewComponentPointerField[C Component](
	ctx MutableContext,
	c C,
) *Field[C]

func NewDataField

func NewDataField[D proto.Message](
	ctx MutableContext,
	d D,
) *Field[D]

re. Data v.s. Component. Components have behavior and has a lifecycle. while Data doesn't and must be attached to a component.

You can define a component just for storing the data, that may contain other information like ref count etc. most importantly, the framework needs to know when it's safe to delete the data. i.e. the lifecycle of that data component reaches completed.

func NewDataPointerField

func NewDataPointerField[D proto.Message](
	ctx MutableContext,
	d D,
) *Field[D]

func (*Field[T]) Get

func (d *Field[T]) Get(Context) (T, error)

type Library

type Library interface {
	Name() string
	Components() []*RegistrableComponent
	Tasks() []*RegistrableTask
	// contains filtered or unexported methods
}

type LifecycleState

type LifecycleState int

Shall it be named ComponentLifecycleState?

const (
	LifecycleStateCreated LifecycleState = 1 << iota
	LifecycleStateRunning
	// LifecycleStatePaused // <- this can also be a method of the engine: PauseComponent
	LifecycleStateCompleted
	LifecycleStateFailed

	LifecycleStateUnspecified = LifecycleState(0)
)

type MockComponent

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

MockComponent is a mock of Component interface.

func NewMockComponent

func NewMockComponent(ctrl *gomock.Controller) *MockComponent

NewMockComponent creates a new mock instance.

func (*MockComponent) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockComponent) LifecycleState

func (m *MockComponent) LifecycleState() LifecycleState

LifecycleState mocks base method.

type MockComponentMockRecorder

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

MockComponentMockRecorder is the mock recorder for MockComponent.

func (*MockComponentMockRecorder) LifecycleState

func (mr *MockComponentMockRecorder) LifecycleState() *gomock.Call

LifecycleState indicates an expected call of LifecycleState.

type MockLibrary

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

MockLibrary is a mock of Library interface.

func NewMockLibrary

func NewMockLibrary(ctrl *gomock.Controller) *MockLibrary

NewMockLibrary creates a new mock instance.

func (*MockLibrary) Components

func (m *MockLibrary) Components() []*RegistrableComponent

Components mocks base method.

func (*MockLibrary) EXPECT

func (m *MockLibrary) EXPECT() *MockLibraryMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockLibrary) Name

func (m *MockLibrary) Name() string

Name mocks base method.

func (*MockLibrary) Tasks

func (m *MockLibrary) Tasks() []*RegistrableTask

Tasks mocks base method.

type MockLibraryMockRecorder

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

MockLibraryMockRecorder is the mock recorder for MockLibrary.

func (*MockLibraryMockRecorder) Components

func (mr *MockLibraryMockRecorder) Components() *gomock.Call

Components indicates an expected call of Components.

func (*MockLibraryMockRecorder) Name

func (mr *MockLibraryMockRecorder) Name() *gomock.Call

Name indicates an expected call of Name.

func (*MockLibraryMockRecorder) Tasks

func (mr *MockLibraryMockRecorder) Tasks() *gomock.Call

Tasks indicates an expected call of Tasks.

type MockTaskHandler

type MockTaskHandler[C any, T any] struct {
	// contains filtered or unexported fields
}

MockTaskHandler is a mock of TaskHandler interface.

func NewMockTaskHandler

func NewMockTaskHandler[C any, T any](ctrl *gomock.Controller) *MockTaskHandler[C, T]

NewMockTaskHandler creates a new mock instance.

func (*MockTaskHandler[C, T]) EXPECT

func (m *MockTaskHandler[C, T]) EXPECT() *MockTaskHandlerMockRecorder[C, T]

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockTaskHandler[C, T]) Execute

func (m *MockTaskHandler[C, T]) Execute(arg0 context.Context, arg1 ComponentRef, arg2 T) error

Execute mocks base method.

func (*MockTaskHandler[C, T]) Validate

func (m *MockTaskHandler[C, T]) Validate(arg0 Context, arg1 C, arg2 T) error

Validate mocks base method.

type MockTaskHandlerMockRecorder

type MockTaskHandlerMockRecorder[C any, T any] struct {
	// contains filtered or unexported fields
}

MockTaskHandlerMockRecorder is the mock recorder for MockTaskHandler.

func (*MockTaskHandlerMockRecorder[C, T]) Execute

func (mr *MockTaskHandlerMockRecorder[C, T]) Execute(arg0, arg1, arg2 any) *gomock.Call

Execute indicates an expected call of Execute.

func (*MockTaskHandlerMockRecorder[C, T]) Validate

func (mr *MockTaskHandlerMockRecorder[C, T]) Validate(arg0, arg1, arg2 any) *gomock.Call

Validate indicates an expected call of Validate.

type MutableContext

type MutableContext interface {
	Context

	AddTask(Component, TaskAttributes, any) error
}

type OperationIntent

type OperationIntent int
const (
	OperationIntentProgress OperationIntent = 1 << iota
	OperationIntentObserve

	OperationIntentUnspecified = OperationIntent(0)
)

type PollComponentRequest

type PollComponentRequest[C Component, I any, O any] struct {
	Ref         ComponentRef
	PredicateFn func(C, Context, I) bool
	OperationFn func(C, MutableContext, I) (O, error)
	Input       I
}

type RegistrableComponent

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

func NewRegistrableComponent

func NewRegistrableComponent[C Component](
	componentType string,
	opts ...RegistrableComponentOption,
) *RegistrableComponent

func (RegistrableComponent) Type

func (rc RegistrableComponent) Type() string

type RegistrableComponentOption

type RegistrableComponentOption func(*RegistrableComponent)

func WithEphemeral

func WithEphemeral() RegistrableComponentOption

func WithShardingFn

func WithShardingFn(
	shardingFn func(EntityKey) string,
) RegistrableComponentOption

func WithSingleCluster

func WithSingleCluster() RegistrableComponentOption

Is there any use case where we don't want to replicate certain instances of a archetype?

type RegistrableTask

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

func NewRegistrableTask

func NewRegistrableTask[C any, T any](
	taskType string,
	handler TaskHandler[C, T],
	opts ...RegistrableTaskOption,
) *RegistrableTask

NOTE: C is not Component but any.

func (RegistrableTask) Type

func (rt RegistrableTask) Type() string

type RegistrableTaskOption

type RegistrableTaskOption func(*RegistrableTask)

type Registry

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

func NewRegistry

func NewRegistry() *Registry

func (*Registry) Register

func (r *Registry) Register(lib Library) error

type TaskAttributes

type TaskAttributes struct {
	ScheduledTime time.Time
	Destination   string
}

type TaskHandler

type TaskHandler[C any, T any] interface {
	Validate(Context, C, T) error
	Execute(context.Context, ComponentRef, T) error
}

type TransitionOption

type TransitionOption func(*transitionOptions)

func WithBusinessIDPolicy

func WithBusinessIDPolicy(
	reusePolicy BusinessIDReusePolicy,
	conflictPolicy BusinessIDConflictPolicy,
) TransitionOption

this only applies to NewEntity and UpdateWithNewEntity

func WithSpeculative

func WithSpeculative() TransitionOption

(only) this transition will not be persisted The next non-speculative transition will persist this transition as well. Compared to the EntityEphemeral() operation on RegistrableComponent, the scope of this operation is limited to a certain transition, while the EntityEphemeral() applies to all transitions. TODO: we need to figure out a way to run the tasks generated in a speculative transition

type UnimplementedComponent

type UnimplementedComponent struct{}

Embed UnimplementedComponent to get forward compatibility

func (UnimplementedComponent) LifecycleState

func (UnimplementedComponent) LifecycleState() LifecycleState

type UnimplementedLibrary

type UnimplementedLibrary struct{}

func (UnimplementedLibrary) Components

func (UnimplementedLibrary) Tasks

Jump to

Keyboard shortcuts

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