store

package
v0.1.15 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("storage closed")

Functions

func Deserialize

func Deserialize(data []byte, v any) error

Deserialize decodes msgpack bytes into the provided value.

func Serialize

func Serialize(v any) ([]byte, error)

Serialize encodes a value to msgpack bytes.

Types

type NoteListOptions added in v0.1.6

type NoteListOptions struct {
	Type     string
	FlowIDs  []string
	Contains string
	AfterID  string
	Limit    int
}

NoteListOptions controls filtering and pagination for note listing.

type NoteMeta added in v0.1.6

type NoteMeta struct {
	NoteID    string    `msgpack:"nid"`
	Type      string    `msgpack:"t"`
	FlowIDs   []string  `msgpack:"fids"`
	Content   string    `msgpack:"c"`
	CreatedAt time.Time `msgpack:"ca"`
	UpdatedAt time.Time `msgpack:"ua"`
}

NoteMeta holds metadata and content for a saved note.

type NoteStore added in v0.1.6

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

NoteStore manages notes with thread-safe access and reverse index for flow lookups.

func NewNoteStore added in v0.1.6

func NewNoteStore(storage Storage) *NoteStore

NewNoteStore creates a new NoteStore backed by the given storage.

func (*NoteStore) Close added in v0.1.6

func (s *NoteStore) Close() error

func (*NoteStore) Count added in v0.1.6

func (s *NoteStore) Count() int

Count returns the number of stored notes.

func (*NoteStore) Delete added in v0.1.6

func (s *NoteStore) Delete(noteID string) error

Delete removes a note and cleans up the reverse index.

func (*NoteStore) ForFlowIDs added in v0.1.6

func (s *NoteStore) ForFlowIDs(flowIDs []string) map[string][]*NoteMeta

ForFlowIDs returns notes associated with the given flow IDs, grouped by flow_id.

func (*NoteStore) Get added in v0.1.6

func (s *NoteStore) Get(noteID string) (*NoteMeta, bool)

Get retrieves a note by ID.

func (*NoteStore) List added in v0.1.6

func (s *NoteStore) List(opts NoteListOptions) []*NoteMeta

List returns notes matching the given options, sorted by created_at.

func (*NoteStore) Save added in v0.1.6

func (s *NoteStore) Save(note *NoteMeta) error

Save upserts a note and maintains the reverse flow index.

func (*NoteStore) SplitReferencedFlows added in v0.1.15

func (s *NoteStore) SplitReferencedFlows(flowIDs []string) ([]string, []string)

SplitReferencedFlows splits the provided flows into referenced by at least one note (left / first) and unknown or unreferenced (right).

type Provider added in v0.1.15

type Provider func(name string) (Storage, error)

Provider allocates a named Storage instance. Backends call this in their constructor and own Close on returned stores.

type ReplayHistoryEntry

type ReplayHistoryEntry struct {
	FlowID    string
	CreatedAt time.Time // When replay was executed

	// Request data (for display and export)
	RawRequest      []byte // pre-rule request (base for replay)
	ModifiedRequest []byte // post-rule request (what was sent); nil if no rules applied
	Method          string
	Host            string
	Path            string
	Scheme          string // "http" or "https"
	Port            int    // original port (0 = infer from scheme)
	Protocol        string // "http/1.1" or "h2"

	// Response data
	RespHeaders []byte
	RespBody    []byte
	RespStatus  int
	Duration    time.Duration

	// Lineage
	SourceFlowID string // Original flow_id that was replayed (empty for request_send)
}

ReplayHistoryEntry stores a replay request/response with positioning info.

type ReplayHistoryMeta

type ReplayHistoryMeta struct {
	FlowID       string        `msgpack:"fid"`
	Method       string        `msgpack:"m"`
	Host         string        `msgpack:"h"`
	Path         string        `msgpack:"p"`
	Scheme       string        `msgpack:"sc,omitempty"` // "http" or "https"
	Port         int           `msgpack:"po,omitempty"` // original port (0 = infer from scheme)
	Protocol     string        `msgpack:"pr"`
	SourceFlowID string        `msgpack:"sf"`
	CreatedAt    time.Time     `msgpack:"ca"`
	RespStatus   int           `msgpack:"rs"`
	RespLen      int           `msgpack:"rl"`
	Duration     time.Duration `msgpack:"d"`
}

ReplayHistoryMeta holds lightweight metadata for a replay entry. Used by summary/list paths to avoid deserializing full request/response bodies.

type ReplayHistoryPayload

type ReplayHistoryPayload struct {
	RawRequest      []byte `msgpack:"rq"`
	ModifiedRequest []byte `msgpack:"mq,omitempty"` // post-rule request; nil if no rules applied
	RespHeaders     []byte `msgpack:"rh"`
	RespBody        []byte `msgpack:"rb"`
}

ReplayHistoryPayload holds the heavy request/response data for a replay entry.

type ReplayHistoryStore

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

ReplayHistoryStore manages replay entries with thread-safe access.

func NewReplayHistoryStore

func NewReplayHistoryStore(storage Storage) *ReplayHistoryStore

NewReplayHistoryStore creates a new ReplayHistoryStore backed by the given storage.

func (*ReplayHistoryStore) Clear

func (s *ReplayHistoryStore) Clear()

Clear removes all entries.

func (*ReplayHistoryStore) Close

func (s *ReplayHistoryStore) Close() error

func (*ReplayHistoryStore) Count

func (s *ReplayHistoryStore) Count() int

Count returns the number of stored replay entries.

func (*ReplayHistoryStore) Delete added in v0.1.15

func (s *ReplayHistoryStore) Delete(flowIDs []string) int

Delete removes replay entries by flow_id. Idempotent; unknown ids are skipped. Returns the number of entries actually removed.

func (*ReplayHistoryStore) Get

func (s *ReplayHistoryStore) Get(flowID string) (*ReplayHistoryEntry, bool)

Get retrieves a replay entry by flow_id.

func (*ReplayHistoryStore) List

List returns all replay entries ordered by creation time.

func (*ReplayHistoryStore) ListMeta

func (s *ReplayHistoryStore) ListMeta() []ReplayHistoryMeta

ListMeta returns lightweight metadata for all replay entries, ordered by creation time.

func (*ReplayHistoryStore) Store

func (s *ReplayHistoryStore) Store(entry *ReplayHistoryEntry)

Store adds a replay entry. Called after successful replay_send/request_send.

type SpillStoreConfig

type SpillStoreConfig struct {
	Dir                 string  // optional, auto-created if empty
	FilePrefix          string  // optional prefix for data file name (e.g. "hist" -> "hist.spill.bin")
	MaxHotBytes         int64   // max value bytes in hot cache
	EvictTargetRatio    float64 // evict to this ratio, higher values evict less
	CompactionThreshold int64   // rewrite file when dead bytes exceed this
	ZSTDLevel           int     // compression level (1-21)
}

SpillStoreConfig configures spillStore behavior.

func DefaultSpillStoreConfig

func DefaultSpillStoreConfig() SpillStoreConfig

DefaultSpillStoreConfig returns config with sensible defaults.

type Storage

type Storage interface {
	Set(key string, blob []byte) error
	Get(key string) ([]byte, bool, error)
	KeySet() []string
	Size() int
	Delete(key string) error
	DeleteAll() error
	Close() error
}

Storage defines the interface for key-value blob storage.

func MemProvider added in v0.1.15

func MemProvider(string) (Storage, error)

MemProvider returns a fresh in-memory Storage for every name.

func NewMemStorage

func NewMemStorage() Storage

NewMemStorage returns an in-memory Storage implementation.

func NewSpillStore

func NewSpillStore(cfg SpillStoreConfig) (Storage, error)

NewSpillStore creates a new spillStore with the given config.

Jump to

Keyboard shortcuts

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