state

package
v0.0.24 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package state reads and deletes records from a Dapr state store.

It is the read model behind the dashboard's State page, and is deliberately separate from pkg/workflow: that package decodes one known key shape into executions, while this one browses the whole keyspace without interpreting what it finds.

Index

Constants

View Source
const (
	EncodingText   = "text"
	EncodingBase64 = "base64"
)

Encoding labels how Value/Preview represent the raw bytes.

View Source
const Delimiter = statestore.KeyDelimiter

Delimiter is the separator Dapr puts between a key's app-id prefix and its logical remainder. Exported so the API layer can validate a write's input and report the key it composed without restating the rule.

Variables

View Source
var (
	// ErrNoStore: no store is configured (or the degraded no-store entry).
	ErrNoStore = errors.New("no state store configured")
	// ErrStoreUnreachable: a known store that could not be opened.
	ErrStoreUnreachable = errors.New("could not connect to state store")
	// ErrNotBrowsable: the store opened but cannot enumerate keys or read
	// record metadata. Dapr's HTTP State API cannot list keys, so there is no
	// fallback for such a store — the page reports it rather than degrading.
	ErrNotBrowsable = errors.New("state store cannot be browsed")
	// ErrNotFound: the requested key does not exist.
	ErrNotFound = errors.New("record not found")
	// ErrExists: the key a write would create is already present, and the
	// write did not ask to overwrite it.
	ErrExists = errors.New("record already exists")
)

Functions

func ComposeKey

func ComposeKey(appID, key string) string

ComposeKey builds the stored key for one app-id prefix and logical key. It is the inverse of classify for the two-segment case.

Types

type DeleteResult

type DeleteResult struct {
	Key   string `json:"key"`
	OK    bool   `json:"ok"`
	Error string `json:"error,omitempty"`
}

DeleteResult reports one key's outcome, so a partial failure names exactly which keys survived.

type Item

type Item struct {
	Key          string     `json:"key"`
	AppID        string     `json:"appId"`
	LogicalKey   string     `json:"logicalKey"`
	Kind         Kind       `json:"kind"`
	Preview      string     `json:"preview"`
	Encoding     string     `json:"encoding"`
	Size         int        `json:"size"`
	ETag         string     `json:"etag,omitempty"`
	TTLExpiresAt *time.Time `json:"ttlExpiresAt,omitempty"`
	ContentType  string     `json:"contentType,omitempty"`
}

Item is one row in a listing: metadata plus a bounded preview, never the full value. The full value comes from Service.Record so that list pages stay small under the dashboard's auto-refresh.

type Kind

type Kind string

Kind is how a key was produced: app code, the workflow engine, or an actor.

const (
	KindApp      Kind = "app"
	KindWorkflow Kind = "workflow"
	KindActor    Kind = "actor"
)

type ListQuery

type ListQuery struct {
	AppID           string
	Search          string
	PageToken       string
	PageSize        int
	IncludeInternal bool
}

ListQuery is one page request. IncludeInternal false — the default — keeps only KindApp records.

type ListResult

type ListResult struct {
	Items     []Item `json:"items"`
	NextToken string `json:"nextToken,omitempty"`
}

ListResult is one page. A non-empty NextToken means "keep paging" even when Items is short: the token has already advanced past every scanned key.

type Record

type Record struct {
	Key          string     `json:"key"`
	AppID        string     `json:"appId"`
	LogicalKey   string     `json:"logicalKey"`
	Kind         Kind       `json:"kind"`
	Value        string     `json:"value"`
	Encoding     string     `json:"encoding"`
	Size         int        `json:"size"`
	Truncated    bool       `json:"truncated"`
	ETag         string     `json:"etag,omitempty"`
	TTLExpiresAt *time.Time `json:"ttlExpiresAt,omitempty"`
	ContentType  string     `json:"contentType,omitempty"`
}

Record is one record's full value plus metadata.

type Service

type Service interface {
	List(ctx context.Context, q ListQuery) (ListResult, error)
	Record(ctx context.Context, key string) (Record, error)
	// AppIDs lists the selectable key prefixes. includeInternal must match the
	// caller's list filter so the dropdown never offers a prefix whose every
	// record that filter hides.
	AppIDs(ctx context.Context, includeInternal bool) ([]string, error)
	Delete(ctx context.Context, keys []string) []DeleteResult
	// Set writes one record at AppID||Key. It reports ErrExists rather than
	// replacing a present key unless the request opts into overwriting.
	Set(ctx context.Context, req SetRequest) error
}

Service is the read + write + delete surface the API needs.

func New

New builds a Service over an opened store. A nil store yields ErrNoStore from every method — cmd builds a degraded entry that way. A non-nil store whose backend does not implement RecordReader yields ErrNotBrowsable.

func NewUnreachable

func NewUnreachable(name, conn string) Service

NewUnreachable builds a Service that always reports ErrStoreUnreachable.

type SetRequest

type SetRequest struct {
	AppID     string
	Key       string
	Value     string
	Overwrite bool
}

SetRequest is one record write. Value is stored verbatim as bytes: Dapr SDKs read values as JSON, but wrapping the text here would mean a pasted JSON object could not be stored as one, so the encoding stays the caller's choice. Overwrite false fails with ErrExists when the key already exists.

Jump to

Keyboard shortcuts

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