fwi

package
v0.0.0-...-9dc1917 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EntityPrefix = "entity_record:"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Aliases

type Aliases interface {
	MakeAlias(ctx context.Context) (string, error)
	DeleteAlias(ctx context.Context, alias string) error
	ListAliases(ctx context.Context) ([]string, error)
}

type Blobs

type Blobs interface {
	Get(ctx context.Context, key string) (io.ReadCloser, error)
	Set(ctx context.Context, key, value string) error
	SetReader(ctx context.Context, key string, r io.Reader) error
	Delete(ctx context.Context, key string) error
	IterateKeys(ctx context.Context, prefix string, offset, limit int) ([]string, error)

	PushScope(scope string)
	PopScope()
}

type Entity

type Entity interface {
	GetName() string
	GetKey() string
	GetUUID() string

	// Use the insi client to bump an integer value
	Bump(ctx context.Context, key string, value int) error
	GetValueStore() KV // Get the value store for the entity
	GetCacheStore() KV // Get the cache store for the entity
	GetEvents() Events // Get the event pub/sub for the entity
	GetBlobs() Blobs   // Get the blob store for the entity
	GetFS() FS         // Get the virtual file system for the entity

	GetAliasManager() Aliases

	// GetUsageInfo retrieves the current usage and limits for the entity.
	GetUsageInfo(ctx context.Context) (*models.LimitsResponse, error)
}

type Events

type Events interface {
	Subscribe(ctx context.Context, topic string, onEvent func(data any)) error
	Publish(ctx context.Context, topic string, data any) error
	Purge(ctx context.Context) (int, error) // Purges subscriptions across ALL nodes

	PushScope(scope string)
	PopScope()
}

type FS

type FS interface {
	// Open opens the named file for reading.
	Open(ctx context.Context, path string) (File, error)
	// Create creates or truncates the named file.
	Create(ctx context.Context, path string) (File, error)
	// Remove removes the named file or directory.
	// By default, it will not remove non-empty directories.
	// Use WithRecursiveRemove to delete a directory and all its contents.
	Remove(ctx context.Context, path string, opts ...RemoveOption) error
	// Mkdir creates a new directory.
	Mkdir(ctx context.Context, path string) error
	// ReadDir reads the directory named by dirname and returns a list of
	// directory entries sorted by filename.
	ReadDir(ctx context.Context, path string) ([]FileInfo, error)
	// Stat returns a FileInfo describing the named file.
	Stat(ctx context.Context, path string) (FileInfo, error)
}

FS represents a virtual file system interface.

func NewVFS

func NewVFS(vs KV, blobs Blobs, logger *slog.Logger) FS

NewVFS creates a new FS instance.

type FWI

type FWI interface {
	// Creates an api key as an admin
	CreateEntity(
		ctx context.Context,
		name string,
		maxlimits models.Limits,
	) (Entity, error)

	// Create or load an entity. If the entity already exists, it will be loaded.
	// If the entity does not exist, it will be created.
	// If the entity is created, the maxlimits will be set.
	// If the entity is loaded, the maxlimits will be ignored.
	CreateOrLoadEntity(
		ctx context.Context,
		name string,
		maxlimits models.Limits,
	) (Entity, error)

	// Load all created entities (we wont have thousands so no need for pagination)
	GetAllEntities(ctx context.Context) ([]Entity, error)

	// Load an entity by name
	GetEntity(ctx context.Context, name string) (Entity, error)

	// Delete an entity
	DeleteEntity(ctx context.Context, name string) error

	// Update the limits for an entity.
	UpdateEntityLimits(ctx context.Context, name string, newLimits models.Limits) error

	// GetOpsPerSecond retrieves the current operations-per-second metrics for the node.
	GetOpsPerSecond(ctx context.Context) (*models.OpsPerSecondCounters, error)

	// IsReady returns true if the initial entity sync has completed successfully.
	IsReady() bool

	// WaitForReady blocks until the initial entity sync completes or the context is cancelled.
	WaitForReady(ctx context.Context) error
}

FWI is the instance that contains a client with the root key When we want to have a user or service delineated, we create an entity and it creates an api key for that entity that seperates that data internally We store the entities and load them by name so we can re-access their data scope The FWI interace is

func NewFWI

func NewFWI(ctx context.Context, insiCfg *client.Config, logger *slog.Logger) (FWI, error)

type File

type File interface {
	io.ReadWriteSeeker
	io.Closer
	Stat() (FileInfo, error)
}

File represents a file in the virtual file system.

type FileInfo

type FileInfo interface {
	Name() string
	Size() int64
	IsDir() bool
	ModTime() time.Time
}

FileInfo provides metadata about a file.

type KV

type KV interface {
	Get(ctx context.Context, key string) (string, error)
	Set(ctx context.Context, key string, value string) error
	IterateKeys(ctx context.Context, prefix string, offset, limit int) ([]string, error)
	Delete(ctx context.Context, key string) error

	CompareAndSwap(ctx context.Context, key string, oldValue, newValue string) error
	SetNX(ctx context.Context, key string, value string) error

	// Adds a scope to the key to scope the data operations to a sub-scope
	// When the system scopes data to an entity (internally) it prefixes by a magic hidden string,
	// we will call "U" All items on the entity are scoped as:
	// U:values U:cache U:events in their respective stores
	// Push-scope is an abstraction layer specific to the fwi package that adds another scope to the kv
	// prefix on the underlying KV storage (cache or values)
	// i.e:			U.scope.scope0.scope1.scope2.key etc
	PushScope(scope string)

	PopScope() // if scope prefix is empty its a no-op
}

Abstracts

type RemoveOption

type RemoveOption func(*removeOptions)

RemoveOption is a functional option for the Remove method.

func WithRecursiveRemove

func WithRecursiveRemove() RemoveOption

WithRecursiveRemove enables recursive deletion of directories.

Jump to

Keyboard shortcuts

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