marshaller

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2025 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Populate added in v0.2.1

func Populate(source any, target any) error

func SyncValue

func SyncValue(ctx context.Context, source any, target any, valueNode *yaml.Node, skipCustomSyncer bool) (node *yaml.Node, err error)

func Unmarshal

func Unmarshal(ctx context.Context, node *yaml.Node, out any) error

func UnmarshalExtension added in v0.2.1

func UnmarshalExtension(keyNode *yaml.Node, valueNode *yaml.Node, extensionsField reflect.Value) error

func UnmarshalKeyValuePair added in v0.2.1

func UnmarshalKeyValuePair(ctx context.Context, keyNode, valueNode *yaml.Node, outValue any) error

func UnmarshalModel added in v0.2.1

func UnmarshalModel(ctx context.Context, node *yaml.Node, structPtr any) error

Types

type CoreAccessor added in v0.2.1

type CoreAccessor[T any] interface {
	GetCore() *T
	SetCore(core *T)
}

CoreAccessor provides type-safe access to the core field in models

type CoreModel added in v0.2.1

type CoreModel struct {
	RootNode *yaml.Node
	Valid    bool
	// contains filtered or unexported fields
}

func (*CoreModel) AddValidationError added in v0.2.1

func (c *CoreModel) AddValidationError(err error)

func (CoreModel) GetRootNode added in v0.2.1

func (c CoreModel) GetRootNode() *yaml.Node

func (CoreModel) GetValid added in v0.2.1

func (c CoreModel) GetValid() bool

func (*CoreModel) GetValidationErrors added in v0.2.1

func (c *CoreModel) GetValidationErrors() []error

func (*CoreModel) SetRootNode added in v0.2.1

func (c *CoreModel) SetRootNode(rootNode *yaml.Node)

func (*CoreModel) SetValid added in v0.2.1

func (c *CoreModel) SetValid(valid bool)

type CoreModeler added in v0.2.1

type CoreModeler interface {
	GetRootNode() *yaml.Node
	SetRootNode(rootNode *yaml.Node)
	GetValid() bool
	SetValid(valid bool)
	AddValidationError(err error)
	GetValidationErrors() []error
}

type CoreSetter added in v0.2.1

type CoreSetter interface {
	SetCoreValue(core any)
}

CoreSetter provides runtime access to set the core field

type Extension added in v0.1.0

type Extension = *yaml.Node

type ExtensionCoreMap

type ExtensionCoreMap interface {
	Get(string) (Node[Extension], bool)
	Set(string, Node[Extension])
	Delete(string)
	All() iter.Seq2[string, Node[Extension]]
	Init()
}

type ExtensionMap

type ExtensionMap interface {
	Set(string, Extension)
	Init()
	SetCore(any)
}

type ExtensionSourceIterator

type ExtensionSourceIterator interface {
	All() iter.Seq2[string, Extension]
}

type Model added in v0.2.1

type Model[T any] struct {
	// Valid indicates whether this model passed validation.
	Valid bool
	// contains filtered or unexported fields
}

Model is a generic model that can be used to validate and marshal/unmarshal a model.

func (*Model[T]) GetCore added in v0.2.1

func (m *Model[T]) GetCore() *T

GetCore will return the low level representation of the model. Useful for accessing line and column numbers for various nodes in the backing yaml/json document.

func (*Model[T]) GetRootNode added in v0.2.1

func (m *Model[T]) GetRootNode() *yaml.Node

GetRootNode implements RootNodeAccessor interface by delegating to the core model.

This method provides access to the unique YAML node that was originally parsed for this model instance. The RootNode serves as a stable identity for the model that persists across array reorderings and other operations.

The method works by checking if the core model implements CoreModeler interface, which provides access to the RootNode. If the core doesn't implement CoreModeler, this returns nil, which causes the sync process to fall back to index-based matching.

This identity-based matching is crucial for preserving field ordering when high-level arrays are reordered, as it ensures each high-level model syncs with its correct corresponding core model rather than being matched by array position.

func (*Model[T]) SetCore added in v0.2.1

func (m *Model[T]) SetCore(core *T)

SetCore implements CoreAccessor interface

func (*Model[T]) SetCoreValue added in v0.2.1

func (m *Model[T]) SetCoreValue(core any)

SetCoreValue implements CoreSetter interface

type Node

type Node[V any] struct {
	Key       string
	KeyNode   *yaml.Node
	Value     V
	ValueNode *yaml.Node
	Present   bool
}

func (Node[V]) GetKeyNodeOrRoot

func (n Node[V]) GetKeyNodeOrRoot(rootNode *yaml.Node) *yaml.Node

func (Node[V]) GetMapKeyNodeOrRoot

func (n Node[V]) GetMapKeyNodeOrRoot(key string, rootNode *yaml.Node) *yaml.Node

Will return the key node for the map key, or the map root node or the provided root node if the node is not present

func (Node[V]) GetMapValueNodeOrRoot

func (n Node[V]) GetMapValueNodeOrRoot(key string, rootNode *yaml.Node) *yaml.Node

Will return the value node for the map key, or the map root node or the provided root node if the node is not present

func (Node[V]) GetNavigableNode

func (n Node[V]) GetNavigableNode() (any, error)

func (Node[V]) GetSliceValueNodeOrRoot

func (n Node[V]) GetSliceValueNodeOrRoot(idx int, rootNode *yaml.Node) *yaml.Node

Will return the value node for the slice index, or the slice root node or the provided root node if the node is not present

func (Node[V]) GetValue

func (n Node[V]) GetValue() any

func (Node[V]) GetValueNodeOrRoot

func (n Node[V]) GetValueNodeOrRoot(rootNode *yaml.Node) *yaml.Node

func (Node[V]) GetValueType

func (n Node[V]) GetValueType() reflect.Type

func (*Node[V]) SetPresent

func (n *Node[V]) SetPresent(present bool)

func (*Node[V]) SyncValue

func (n *Node[V]) SyncValue(ctx context.Context, key string, value any) (*yaml.Node, *yaml.Node, error)

func (*Node[V]) Unmarshal

func (n *Node[V]) Unmarshal(ctx context.Context, keyNode, valueNode *yaml.Node) error

type NodeAccessor

type NodeAccessor interface {
	GetValue() any
	GetValueType() reflect.Type
}

type NodeMutator

type NodeMutator interface {
	Unmarshal(ctx context.Context, keyNode, valueNode *yaml.Node) error
	SetPresent(present bool)
	SyncValue(ctx context.Context, key string, value any) (*yaml.Node, *yaml.Node, error)
}

type Populator added in v0.2.1

type Populator interface {
	Populate(source any) error
}

type RootNodeAccessor added in v0.2.1

type RootNodeAccessor interface {
	GetRootNode() *yaml.Node
}

RootNodeAccessor provides access to the RootNode of a model's core for identity matching.

This interface solves a critical problem in array/map synchronization: when high-level arrays are reordered (e.g., moving workflows around in an Arazzo document), we need to match each high-level element with its corresponding core model to preserve field ordering and other state.

Without identity matching, the sync process would match elements by array position:

Source[0] -> Target[0], Source[1] -> Target[1], etc.

This causes problems when arrays are reordered because the wrong data gets synced to the wrong core objects, disrupting field ordering within individual elements.

With RootNode identity matching, we can match elements correctly:

Source[workflow-A] -> Target[core-for-workflow-A] (regardless of position)
Source[workflow-B] -> Target[core-for-workflow-B] (regardless of position)

The RootNode serves as a unique identity because it's the original YAML node that was parsed for each element, making it a stable identifier across reorderings.

type Syncer

type Syncer interface {
	SyncChanges(ctx context.Context, model any, valueNode *yaml.Node) (*yaml.Node, error)
}

type SyncerWithSyncFunc

type SyncerWithSyncFunc interface {
	SyncChangesWithSyncFunc(ctx context.Context, model any, valueNode *yaml.Node, syncFunc func(context.Context, any, any, *yaml.Node, bool) (*yaml.Node, error)) (*yaml.Node, error)
}

type Unmarshallable

type Unmarshallable interface {
	Unmarshal(ctx context.Context, value *yaml.Node) error
}

Jump to

Keyboard shortcuts

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