transform

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package transform compiles reusable paths and transfers values through Bindly's typed destination binding. It has no handler or transport ownership.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mapping

type Mapping struct {
	From      *Path
	To        string
	Required  bool
	Transform Transform
}

Mapping connects a compiled source path to a typed destination field.

type Path

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

Path is an immutable path over Go structs or JSON-like maps and slices.

func CompilePointer

func CompilePointer(raw string) (*Path, error)

CompilePointer compiles an RFC 6901 pointer. The empty pointer names the root.

func CompileSelector

func CompileSelector(raw string) (*Path, error)

CompileSelector compiles an exact dot/bracket path such as Scope.Items[0].ID. Empty segments, forgiving separators and implicit roots are rejected.

func (*Path) Assign

func (p *Path) Assign(root map[string]any, value any) error

Assign writes into a JSON-like object. It creates object parents only; arrays must already exist and conflicting/scalar paths fail explicitly.

func (*Path) ForType

func (p *Path) ForType(root reflect.Type) (*Path, error)

ForType returns a separate immutable path with struct field indexes planned for one declared source type. The caller's Path is never modified.

func (*Path) Select

func (p *Path) Select(root any) (any, bool, error)

Select distinguishes absent values from present nulls. It never coerces a scalar, guesses a root, or treats a signed index as an object key on arrays.

func (*Path) String

func (p *Path) String() string

func (*Path) ValidateType

func (p *Path) ValidateType(root reflect.Type) error

ValidateType checks every statically known segment. Dynamic interface and string-map contents are checked by Select at invocation time.

type Plan

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

Plan is immutable and safe for concurrent invocations. Bindly owns all destination field access, pointer allocation, and JSON type conversion.

func Compile

func Compile(destination reflect.Type, mappings []Mapping) (*Plan, error)

func CompileFor

func CompileFor(source, destination reflect.Type, mappings []Mapping) (*Plan, error)

CompileFor additionally validates statically known source fields against a declared source type; no first-invocation source shape is cached.

func (*Plan) Apply

func (p *Plan) Apply(ctx context.Context, source, destination any) error

Apply reads one source value per mapping, then asks Bindly to populate the typed destination. JSON encoding preserves json.Number IDs and makes scalar conversion strict (a quoted number cannot populate an integer field).

func (*Plan) Value

func (p *Plan) Value(ctx context.Context, source any) (any, error)

Value allocates and populates a new destination value for codec use.

type Tag

type Tag struct {
	From, To, Codec string
}

Tag is one original Datly transfer declaration, with an exact source path and optional named codec supplied by the caller.

func Tags

func Tags(destination reflect.Type) ([]Tag, error)

Tags reads transfer tags from exported destination fields, including nested structs. Cyclic destinations are visited once along each path.

type Transform

type Transform func(context.Context, any) (any, error)

Transform is an optional, caller-supplied value codec. Plans never choose codecs by name or retain invocation state.

Jump to

Keyboard shortcuts

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