values

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: LGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package values provides typed variable and array implementations for BPMN data handling.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetPath added in v0.9.0

func SetPath(
	ctx context.Context, root data.Value, path string, v data.Value,
) error

SetPath sets v at the structural path within root — a path relative to root, "items[0].price" or "[0].total" (ADR-011 v.6 §2.9.3). It walks to the parent of the last step, creating missing intermediate records/lists on a permissive dynamic target (a following ".field" → a values.Record, a following "[i]" → a values.Array), then sets the last step via Record.SetField or Collection.SetAt. An empty path is an error — a whole-value write is Value.Update.

It lives in `values` (not `data`) because auto-vivify constructs concrete values.Record / values.Array, and `data` cannot import `values`.

Types

type Array

type Array[T any] struct {
	// contains filtered or unexported fields
}

Array is a implementation of the data.Collection and data.Value interfaces.

func NewArray

func NewArray[T any](values ...T) *Array[T]

NewArray creates a new Array of T type, fill it with values and returns its pointer

func (*Array[T]) Add

func (a *Array[T]) Add(_ context.Context, value any) error

Add adds new value into the end of the collection. If there is any problem occurred, then error returned.

func (*Array[T]) AddT

func (a *Array[T]) AddT(value T) error

AddT is a typed version of Add.

func (*Array[T]) Clear

func (a *Array[T]) Clear()

Clear removes all elements in the collection and sets index to -1.

func (*Array[T]) Clone added in v0.1.1

func (a *Array[T]) Clone() data.Value

Clone creates a clone of the Array with copies of the Array's elemnts, preserving the iteration cursor so the clone resumes at the same position.

func (*Array[T]) Count

func (a *Array[T]) Count() int

Count returns legth of the collection.

func (*Array[T]) Delete

func (a *Array[T]) Delete(_ context.Context, index any) error

Delete removes collection element on index position.

func (*Array[T]) DeleteT

func (a *Array[T]) DeleteT(index int) error

DeleteT is a typed version of Delete.

func (*Array[T]) Get

func (a *Array[T]) Get(_ context.Context) any

Get returns value of the Value. For collection Get retrieves element with current index if collection is empty then panic will be fired.

func (*Array[T]) GetAll

func (a *Array[T]) GetAll(_ context.Context) []any

GetAll returns all values of the collection.

func (*Array[T]) GetAllT

func (a *Array[T]) GetAllT() []T

GetAllT is a typed version of GetAll.

func (*Array[T]) GetAt

func (a *Array[T]) GetAt(_ context.Context, index any) (any, error)

GetAt tries to retrieve a values at index and returns it on success or returns error on failure.

func (*Array[T]) GetAtT

func (a *Array[T]) GetAtT(index int) (T, error)

GetAtT is typed version of GetAt.

func (*Array[T]) GetKeys

func (a *Array[T]) GetKeys() []any

GetKeys returns a list of keys

func (*Array[T]) GetKeysT

func (a *Array[T]) GetKeysT() []int

GetKeysT is a typed version of GetKeys.

func (*Array[T]) GetP

func (a *Array[T]) GetP() *T

GetP returns the pointer of the Value's value. It could be used for direct update of the value. To guarantee of the thread safety use Lock/Unlock of the Value.

func (*Array[T]) GetT

func (a *Array[T]) GetT() T

GetT is a typed version of Get.

func (*Array[T]) GoTo

func (a *Array[T]) GoTo(index any) error

GoTo sets collection current index to desired position. first element has 0 index.

func (*Array[T]) GoToT

func (a *Array[T]) GoToT(index int) error

GoToT is a typed version of GoTo. if index is negative, then collection index goes backward on index steps.

func (*Array[T]) Index

func (a *Array[T]) Index() any

Index returns current index in the collection. Index is -1 on empty collection.

func (*Array[T]) IndexT

func (a *Array[T]) IndexT() int

IndexT is a typed version of Index.

func (*Array[T]) Insert

func (a *Array[T]) Insert(_ context.Context, value, index any) error

Insert adds new value at index.

func (*Array[T]) InsertT

func (a *Array[T]) InsertT(value T, index int) error

InsertT is a typed version of Insert.

func (*Array[T]) Lock

func (a *Array[T]) Lock()

Lock locks Value's internal mutex in case user need to update internal Value throug its pointer.

func (*Array[T]) Next

func (a *Array[T]) Next(dir data.StepDirection) error

Next shifts current index of the collection for given distance. if distance is negative then index shifted backwards.

func (*Array[T]) Rewind

func (a *Array[T]) Rewind()

Rewind sets current index in collection to 0.

func (*Array[T]) SetAt added in v0.9.0

func (a *Array[T]) SetAt(_ context.Context, index, value any) error

SetAt sets the element at index (data.Collection): an index in [0, len) replaces, index == len appends (seating the cursor if the collection was empty, as Add does), index > len (or negative) is an OutOfRangeError. It does not move the iteration cursor.

func (*Array[T]) SetAtT added in v0.9.0

func (a *Array[T]) SetAtT(index int, value T) error

SetAtT is a typed version of SetAt.

func (*Array[T]) Type

func (a *Array[T]) Type() string

Type returns string representation of the Value's type.

func (*Array[T]) Unlock

func (a *Array[T]) Unlock()

Unlock unlocks internal Value's mutex.

func (*Array[T]) Update

func (a *Array[T]) Update(_ context.Context, value any) error

Update sets new value of the Value. For collection Update changes element with current index if collection is empty then panic will be fired.

func (*Array[T]) UpdateT

func (a *Array[T]) UpdateT(value T) error

UpdateT is a typed version of Update.

type Map added in v0.10.0

type Map[T any] struct {
	// contains filtered or unexported fields
}

Map is the generic dynamic map value — the concrete of the fourth structural kind (ADR-011 v.7 §2.9.7, SRD-047 FR-2): homogeneous T values under non-empty string data keys. It mirrors Array[T] — homogeneity is enforced by the type parameter, Map[any] is the zero-setup dictionary for engine-assembled data — and, unlike Collection, carries no iteration cursor: sorted Keys plus Entry is the complete, stateless enumeration.

func EmptyMap added in v0.11.0

func EmptyMap[T any]() *Map[T]

EmptyMap returns a Map with no entries.

It is total: NewMap's only error source is the loop that rejects an empty key, so the no-entry path can never fail. Expressing it as its own function lets production code build an empty map without a panicking constructor — MustMap stays for tests and examples.

func MustMap added in v0.10.0

func MustMap[T any](entries map[string]T) *Map[T]

MustMap is NewMap that panics on error — for tests and static process construction.

func NewMap added in v0.10.0

func NewMap[T any](entries map[string]T) (*Map[T], error)

NewMap creates a Map of T from entries, copying the input (nil is allowed — an empty map). An empty-string key in the input is a classified error — map keys are non-empty arbitrary strings (SRD-047 §4.2).

func (*Map[T]) Clone added in v0.10.0

func (m *Map[T]) Clone() data.Value

Clone creates a clone of the Map with a copy of its entries (the Array[T] element-copy contract).

func (*Map[T]) DeleteEntry added in v0.10.0

func (m *Map[T]) DeleteEntry(_ context.Context, key string) error

DeleteEntry removes the entry under key, or returns a classified ObjectNotFound error when it is absent (fail-loud, like Entry).

func (*Map[T]) Entry added in v0.10.0

func (m *Map[T]) Entry(_ context.Context, key string) (any, error)

Entry returns the value stored under key, or a classified ObjectNotFound error when the entry is absent.

func (*Map[T]) EntryT added in v0.10.0

func (m *Map[T]) EntryT(key string) (T, error)

EntryT returns the typed value stored under key, or a classified ObjectNotFound error when the entry is absent — the typed twin of Entry (the array_t.go helper convention).

func (*Map[T]) Get added in v0.10.0

func (m *Map[T]) Get(_ context.Context) any

Get returns the whole map as a plain-Go snapshot: a map[string]T copy — safe to read and mutate.

func (*Map[T]) Keys added in v0.10.0

func (m *Map[T]) Keys() []string

Keys returns all entry keys in ascending (sorted) order — the deterministic enumeration over Go's randomized map iteration (SRD-047 NFR-1).

func (*Map[T]) Lock added in v0.10.0

func (m *Map[T]) Lock()

Lock locks the Map's internal mutex.

func (*Map[T]) SetEntry added in v0.10.0

func (m *Map[T]) SetEntry(_ context.Context, key string, value any) error

SetEntry upserts the entry under key — permissive on the key (keys are data), owner-enforced on the value (the checkValue[T] contract Array[T] shares). An empty key is a classified error.

func (*Map[T]) SetEntryT added in v0.10.0

func (m *Map[T]) SetEntryT(key string, value T) error

SetEntryT upserts the typed entry under key — the typed twin of SetEntry. An empty key is a classified error.

func (*Map[T]) Type added in v0.10.0

func (m *Map[T]) Type() string

Type returns the name of the Map's element type (the Array[T] convention).

func (*Map[T]) Unlock added in v0.10.0

func (m *Map[T]) Unlock()

Unlock unlocks the Map's internal mutex.

func (*Map[T]) Update added in v0.10.0

func (m *Map[T]) Update(_ context.Context, value any) error

Update REPLACES the whole entry set with the given map[string]T (ADR-011 v.7 §2.9.7 — replace, not merge, so Get/Update round-trip and a replace can express deletion; per-entry surgery is SetEntry/DeleteEntry). Any other payload shape and an empty-string key are classified errors.

type Record added in v0.9.0

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

Record is the dynamic, engine-assembled record value — the zero-setup tier of ADR-011 v.6 §2.9.5. It is a string-keyed, insertion-ordered, heterogeneous set of field Values; it implements data.Value and the data.Record capability, so a structural path ("order.items[0].price") navigates into it via Field. It is permissive: SetField adds an unknown field (native-struct-backed records that reject unknown fields are the S4 adapter tier).

func EmptyRecord added in v0.11.0

func EmptyRecord() *Record

EmptyRecord returns a Record with no fields.

It is total: NewRecord's only error source is the loop that validates its fields, so the no-field path can never fail. Expressing it as its own function lets production code build an empty record without a panicking constructor — MustRecord stays for tests and examples.

func MustRecord added in v0.9.0

func MustRecord(fields ...RecordField) *Record

MustRecord is NewRecord that panics on error — for tests and static process construction.

func NewRecord added in v0.9.0

func NewRecord(fields ...RecordField) (*Record, error)

NewRecord creates a Record from the given fields, in order. A field name must be CheckName-legal (so every field is addressable by a structural path) and a field value must not be nil; a duplicate name is rejected.

func (*Record) Clone added in v0.9.0

func (r *Record) Clone() data.Value

Clone deep-clones the Record: a fresh Record with each field's Value.Clone, preserving insertion order.

func (*Record) Field added in v0.9.0

func (r *Record) Field(_ context.Context, name string) (data.Value, error)

Field returns the named field's value, or a classified ObjectNotFound error when the field is absent.

func (*Record) Get added in v0.9.0

func (r *Record) Get(ctx context.Context) any

Get returns the whole record as a deep plain-Go snapshot: a map[string]any keyed by field name, each field via its own Value.Get (a nested record yields a nested map). The snapshot is a copy — safe to read and mutate.

func (*Record) Keys added in v0.9.0

func (r *Record) Keys() []string

Keys returns the field names in insertion order.

func (*Record) Lock added in v0.9.0

func (r *Record) Lock()

Lock locks the Record's internal mutex.

func (*Record) SetField added in v0.9.0

func (r *Record) SetField(_ context.Context, name string, v data.Value) error

SetField adds or replaces the named field. The name must be CheckName-legal and the value non-nil; a new name is appended to the field order.

func (*Record) Type added in v0.9.0

func (r *Record) Type() string

Type returns the Record's type name.

func (*Record) Unlock added in v0.9.0

func (r *Record) Unlock()

Unlock unlocks the Record's internal mutex.

func (*Record) Update added in v0.9.0

func (r *Record) Update(ctx context.Context, value any) error

Update replaces matching fields from a map[string]any: each entry whose key is an existing field updates that field's Value; unknown keys and a non-map value are rejected, so whole-value Update stays shape-preserving.

type RecordField added in v0.9.0

type RecordField struct {
	V    data.Value
	Name string
}

RecordField is one field of a Record: a name and its value.

func F added in v0.9.0

func F(name string, v data.Value) RecordField

F is a shorthand for a RecordField literal.

type Variable

type Variable[T any] struct {
	// contains filtered or unexported fields
}

Variable represents a generic variable value.

func NewVariable

func NewVariable[T any](value T) *Variable[T]

NewVariable creates a new variable of type T.

func (*Variable[T]) Clone added in v0.1.1

func (v *Variable[T]) Clone() data.Value

Clone creates a clone of the Variable with same value.

func (*Variable[T]) Get

func (v *Variable[T]) Get(_ context.Context) any

Get returns value of the Value.

func (*Variable[T]) GetP

func (v *Variable[T]) GetP() *T

GetP returns the pointer of the Value's value. It could be used for direct update of the value. To guarantee of the thread safety use Lock/Unlock of the Value.

DO NOT TRY to update inner value on GetP call as followed:

v.Lock()
v.GetP().inner_value = new_value
v.Unlock()

BECAUSE IT LEADS to DEADLOCK

Use followed pattern:

pv := v.GetP()
v.Lock()
pv.inner_value = new_value
v.Unlock()

func (*Variable[T]) GetT

func (v *Variable[T]) GetT() T

GetT returns typed value of the Value.

func (*Variable[T]) Lock

func (v *Variable[T]) Lock()

Lock locks Value's internal mutex in case user need to update internal Value throug its pointer.

func (*Variable[T]) Type

func (v *Variable[T]) Type() string

Type returns string representation of the Value's type.

func (*Variable[T]) Unlock

func (v *Variable[T]) Unlock()

Unlock unlocks internal Value's mutex.

func (*Variable[T]) Update

func (v *Variable[T]) Update(_ context.Context, value any) error

Update sets new value of the Value. For collection Update changes element with current index if collection is empty then panic will be fired.

func (*Variable[T]) UpdateT

func (v *Variable[T]) UpdateT(value T) error

UpdateT sets new typed value of the Value.

Jump to

Keyboard shortcuts

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