Documentation
¶
Overview ¶
Package values provides typed variable and array implementations for BPMN data handling.
Index ¶
- func SetPath(ctx context.Context, root data.Value, path string, v data.Value) error
- type Array
- func (a *Array[T]) Add(_ context.Context, value any) error
- func (a *Array[T]) AddT(value T) error
- func (a *Array[T]) Clear()
- func (a *Array[T]) Clone() data.Value
- func (a *Array[T]) Count() int
- func (a *Array[T]) Delete(_ context.Context, index any) error
- func (a *Array[T]) DeleteT(index int) error
- func (a *Array[T]) Get(_ context.Context) any
- func (a *Array[T]) GetAll(_ context.Context) []any
- func (a *Array[T]) GetAllT() []T
- func (a *Array[T]) GetAt(_ context.Context, index any) (any, error)
- func (a *Array[T]) GetAtT(index int) (T, error)
- func (a *Array[T]) GetKeys() []any
- func (a *Array[T]) GetKeysT() []int
- func (a *Array[T]) GetP() *T
- func (a *Array[T]) GetT() T
- func (a *Array[T]) GoTo(index any) error
- func (a *Array[T]) GoToT(index int) error
- func (a *Array[T]) Index() any
- func (a *Array[T]) IndexT() int
- func (a *Array[T]) Insert(_ context.Context, value, index any) error
- func (a *Array[T]) InsertT(value T, index int) error
- func (a *Array[T]) Lock()
- func (a *Array[T]) Next(dir data.StepDirection) error
- func (a *Array[T]) Rewind()
- func (a *Array[T]) SetAt(_ context.Context, index, value any) error
- func (a *Array[T]) SetAtT(index int, value T) error
- func (a *Array[T]) Type() string
- func (a *Array[T]) Unlock()
- func (a *Array[T]) Update(_ context.Context, value any) error
- func (a *Array[T]) UpdateT(value T) error
- type Map
- func (m *Map[T]) Clone() data.Value
- func (m *Map[T]) DeleteEntry(_ context.Context, key string) error
- func (m *Map[T]) Entry(_ context.Context, key string) (any, error)
- func (m *Map[T]) EntryT(key string) (T, error)
- func (m *Map[T]) Get(_ context.Context) any
- func (m *Map[T]) Keys() []string
- func (m *Map[T]) Lock()
- func (m *Map[T]) SetEntry(_ context.Context, key string, value any) error
- func (m *Map[T]) SetEntryT(key string, value T) error
- func (m *Map[T]) Type() string
- func (m *Map[T]) Unlock()
- func (m *Map[T]) Update(_ context.Context, value any) error
- type Record
- func (r *Record) Clone() data.Value
- func (r *Record) Field(_ context.Context, name string) (data.Value, error)
- func (r *Record) Get(ctx context.Context) any
- func (r *Record) Keys() []string
- func (r *Record) Lock()
- func (r *Record) SetField(_ context.Context, name string, v data.Value) error
- func (r *Record) Type() string
- func (r *Record) Unlock()
- func (r *Record) Update(ctx context.Context, value any) error
- type RecordField
- type Variable
- func (v *Variable[T]) Clone() data.Value
- func (v *Variable[T]) Get(_ context.Context) any
- func (v *Variable[T]) GetP() *T
- func (v *Variable[T]) GetT() T
- func (v *Variable[T]) Lock()
- func (v *Variable[T]) Type() string
- func (v *Variable[T]) Unlock()
- func (v *Variable[T]) Update(_ context.Context, value any) error
- func (v *Variable[T]) UpdateT(value T) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetPath ¶ added in v0.9.0
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 (*Array[T]) Add ¶
Add adds new value into the end of the collection. If there is any problem occurred, then error returned.
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
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]) Get ¶
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]) GetAt ¶
GetAt tries to retrieve a values at index and returns it on success or returns error on failure.
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]) GoTo ¶
GoTo sets collection current index to desired position. first element has 0 index.
func (*Array[T]) GoToT ¶
GoToT is a typed version of GoTo. if index is negative, then collection index goes backward on index steps.
func (*Array[T]) Index ¶
Index returns current index in the collection. Index is -1 on empty collection.
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]) SetAt ¶ added in v0.9.0
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.
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
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
MustMap is NewMap that panics on error — for tests and static process construction.
func NewMap ¶ added in v0.10.0
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
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
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
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
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
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
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]) SetEntry ¶ added in v0.10.0
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
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
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
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
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
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
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) 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
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) Unlock ¶ added in v0.9.0
func (r *Record) Unlock()
Unlock unlocks the Record's internal mutex.
type RecordField ¶ added in v0.9.0
RecordField is one field of a Record: a name and its value.
type Variable ¶
type Variable[T any] struct { // contains filtered or unexported fields }
Variable represents a generic variable value.
func NewVariable ¶
NewVariable creates a new variable of type T.
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]) Lock ¶
func (v *Variable[T]) Lock()
Lock locks Value's internal mutex in case user need to update internal Value throug its pointer.