domain

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Overview

Package domain contains Foundry's shared domain primitives.

This package is for value objects and pure helpers that are used across configuration loading, molding, casting, patching, and writing. Examples include structured materials, opaque blob materials, template wrappers, addresses, formats, pointer helpers, and serialization helpers.

Keep this package free of orchestration and side effects. It must not decide which pipeline phase runs, select deployment implementations, execute tools, write files, read user configuration, or contain platform-specific rendering behavior. Put that logic in the package that owns the behavior instead.

The only Foundry package this package may import is internal/errors. Do not import api/v1alpha1 or any internal orchestration, casting, molding, infrastructure, writer, tooler, config, or ledger package from here.

Index

Constants

This section is empty.

Variables

View Source
var (
	EventGauge   = Event{/* contains filtered or unexported fields */}
	EventForge   = Event{/* contains filtered or unexported fields */}
	EventCast    = Event{/* contains filtered or unexported fields */}
	EventCatalog = Event{/* contains filtered or unexported fields */}
)
View Source
var (
	FormatYAML = Format{/* contains filtered or unexported fields */}
	FormatJSON = Format{/* contains filtered or unexported fields */}
	FormatINI  = Format{/* contains filtered or unexported fields */}
	FormatText = Format{/* contains filtered or unexported fields */}
)

Functions

func MarshalYAML

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

func MergeYAML

func MergeYAML(base, override string) (string, error)

MergeYAML takes a base YAML string and an override YAML string, and returns a new YAML string with deep merge — override keys win at every level, base-only keys are preserved.

func MustMarshalYAML

func MustMarshalYAML(v any) []byte

func MustNewFileFromFS

func MustNewFileFromFS(fs embed.FS, path string) []byte

func MustUnmarshalYAML

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

func NewBoolPtr

func NewBoolPtr(i bool) *bool

func NewIntPtr

func NewIntPtr(i int) *int

func UnmarshalYAML

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

Types

type Address

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

func MustNewAddress

func MustNewAddress(scheme, host string, port int) Address

func NewAddress

func NewAddress(scheme, host string, port int) (Address, error)

NewAddress requires a non-empty scheme and host, and a port in [0, 65535] where 0 means no port.

func ParseAddress

func ParseAddress(raw string) (Address, error)

ParseAddress accepts "scheme://host[:port]"; IPv6 literals must be bracketed (e.g. "tcp://[::1]:9000" or "tcp://[::1]").

func ParseAddresses

func ParseAddresses(raws []string) ([]Address, error)

func (Address) Host

func (a Address) Host() string

func (Address) Port

func (a Address) Port() int

func (Address) Scheme

func (a Address) Scheme() string

func (Address) String

func (a Address) String() string

String renders the address as "scheme://host[:port]", bracketing IPv6 hosts and omitting the port suffix when port is zero.

type BlobMaterial

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

func NewBlobMaterial

func NewBlobMaterial(contents []byte, path string) BlobMaterial

func (BlobMaterial) FmtContents

func (m BlobMaterial) FmtContents() []byte

func (BlobMaterial) Path

func (m BlobMaterial) Path() string

type DistinctID

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

DistinctID is an anonymous, stable identifier for telemetry attribution. It is at most 32 characters and never reveals the source from which it was derived; values longer than 32 characters are truncated by NewDistinctID.

func MustNewDistinctID

func MustNewDistinctID() DistinctID

func NewDistinctID

func NewDistinctID() (DistinctID, error)

func UnknownDistinctID

func UnknownDistinctID() DistinctID

UnknownDistinctID is the sentinel used when no stable raw identifier could be derived.

func (DistinctID) String

func (d DistinctID) String() string

type Event

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

Event names a foundryctl pipeline operation tracked by the ledger. An Event carries an optional past-tense outcome (succeeded or failed) so that ledger adapters see a finite, stable vocabulary like "forge succeeded" or "forge failed" rather than a single name disambiguated by a property.

func MustNewEvent

func MustNewEvent(s string) Event

func NewEvent

func NewEvent(s string) (Event, error)

NewEvent accepts only the names of declared base Event values. The returned Event has no outcome; use Succeeded or Failed to attach one.

func (Event) Failed

func (e Event) Failed() Event

Failed returns a copy of e with the failure outcome attached.

func (Event) String

func (e Event) String() string

String renders the event as "<name>" or "<name> <outcome>".

func (Event) Succeeded

func (e Event) Succeeded() Event

Succeeded returns a copy of e with the success outcome attached.

type Format

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

Format identifies the syntax of a Material's contents and carries the constructor that wraps a rendered byte stream in the matching concrete Material type. To register a new format, add a single entry above with its New* constructor — Template.Render picks it up automatically.

func (Format) NewMaterial

func (f Format) NewMaterial(contents []byte, path string) (Material, error)

NewMaterial wraps contents in the concrete Material type for this format.

func (Format) String

func (f Format) String() string

type INIMaterial

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

func MustNewINIMaterial

func MustNewINIMaterial(contents []byte, path string) INIMaterial

func NewINIMaterial

func NewINIMaterial(contents []byte, path string) (INIMaterial, error)

func (INIMaterial) CloneWithJSONContents

func (m INIMaterial) CloneWithJSONContents(contents []byte) StructuredMaterial

func (INIMaterial) FmtContents

func (m INIMaterial) FmtContents() []byte

func (INIMaterial) GetBytes

func (m INIMaterial) GetBytes(path string) ([]byte, error)

func (INIMaterial) GetStringSlice

func (m INIMaterial) GetStringSlice(path string) ([]string, error)

func (INIMaterial) HasMultipleDocuments

func (m INIMaterial) HasMultipleDocuments() bool

func (INIMaterial) JSONContents

func (m INIMaterial) JSONContents() []byte

func (INIMaterial) Path

func (m INIMaterial) Path() string

type JSONMaterial

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

func MustNewJSONMaterial

func MustNewJSONMaterial(contents []byte, path string) JSONMaterial

func NewJSONMaterial

func NewJSONMaterial(contents []byte, path string) (JSONMaterial, error)

func (JSONMaterial) CloneWithJSONContents

func (m JSONMaterial) CloneWithJSONContents(contents []byte) StructuredMaterial

func (JSONMaterial) FmtContents

func (m JSONMaterial) FmtContents() []byte

func (JSONMaterial) GetBytes

func (m JSONMaterial) GetBytes(path string) ([]byte, error)

func (JSONMaterial) GetStringSlice

func (m JSONMaterial) GetStringSlice(path string) ([]string, error)

func (JSONMaterial) HasMultipleDocuments

func (m JSONMaterial) HasMultipleDocuments() bool

func (JSONMaterial) JSONContents

func (m JSONMaterial) JSONContents() []byte

func (JSONMaterial) Path

func (m JSONMaterial) Path() string

type Material

type Material interface {
	Path() string

	// FmtContents returns the bytes in their human-readable, on-disk form. This
	// is the form Foundry writes out, distinct from the canonical form used for
	// traversal and patching.
	FmtContents() []byte
}

Material is a unit of output that Foundry produces. It carries the path it should be written to and the bytes to write there.

type Properties

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

Properties is a string-keyed bag of telemetry values with a fixed shape for the success/error envelope (see WithSuccess and WithError). Set, WithSuccess, and WithError mutate the underlying map and return the receiver for chaining.

func NewProperties

func NewProperties() Properties

func (Properties) Map

func (p Properties) Map() map[string]any

Map returns a copy of the underlying values, safe for callers to mutate.

func (Properties) Set

func (p Properties) Set(key string, value any) Properties

func (Properties) WithError

func (p Properties) WithError(err error) Properties

WithError records that the tracked operation failed and stores the typed error kind, its message, and the underlying cause so analytics can group failures by class while preserving the wrapped detail.

func (Properties) WithSuccess

func (p Properties) WithSuccess() Properties

WithSuccess records that the tracked operation succeeded.

type StructuredMaterial

type StructuredMaterial interface {
	Material

	// JSONContents returns the canonical JSON form used for traversal and
	// patching. JSON is the contract: callers (e.g. jsonpatch) operate on it
	// directly.
	JSONContents() []byte

	// HasMultipleDocuments reports whether the material groups multiple
	// top-level documents under one path (currently only multi-document YAML).
	// Callers use this to choose between scalar and array traversal of
	// JSONContents.
	HasMultipleDocuments() bool

	CloneWithJSONContents(contents []byte) StructuredMaterial

	// GetBytes returns the value at the given path as bytes. The path uses
	// gjson dotted-key syntax (e.g. "service.name", "service.names.0"), not
	// JSON Pointer.
	GetBytes(path string) ([]byte, error)

	// GetStringSlice returns the slice at the given path as strings. See
	// GetBytes for path syntax.
	GetStringSlice(path string) ([]string, error)
}

StructuredMaterial is a Material whose contents are structured data with a navigable shape, supporting in-place reads and patches against a canonical representation.

type Template

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

Template is a parsed text/template paired with the on-disk path it was loaded from and the Format its rendered output is expected to take. Format drives Render's choice of concrete Material type.

func MustNewTemplate

func MustNewTemplate(name string, contents []byte, format Format) *Template

func MustNewTemplateFromFS

func MustNewTemplateFromFS(fs embed.FS, path string, format Format) *Template

func NewTemplate

func NewTemplate(name string, contents []byte, format Format) (*Template, error)

func NewTemplateFromFS

func NewTemplateFromFS(fs embed.FS, path string, format Format) (*Template, error)

func (*Template) Execute

func (t *Template) Execute(w io.Writer, data any) error

Execute renders the template into w. Each call clones the underlying *template.Template so concurrent calls don't share parse state.

func (*Template) Format

func (t *Template) Format() Format

func (*Template) Name

func (t *Template) Name() string

func (*Template) Path

func (t *Template) Path() string

func (*Template) Render

func (t *Template) Render(data any, path string) (Material, error)

Render executes the template against data and wraps the output in the concrete Material type indicated by the template's Format.

type YAMLMaterial

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

func MustNewYAMLMaterial

func MustNewYAMLMaterial(contents []byte, path string) YAMLMaterial

func NewYAMLMaterial

func NewYAMLMaterial(contents []byte, path string) (YAMLMaterial, error)

func (YAMLMaterial) CloneWithJSONContents

func (m YAMLMaterial) CloneWithJSONContents(contents []byte) StructuredMaterial

func (YAMLMaterial) FmtContents

func (m YAMLMaterial) FmtContents() []byte

func (YAMLMaterial) GetBytes

func (m YAMLMaterial) GetBytes(path string) ([]byte, error)

func (YAMLMaterial) GetStringSlice

func (m YAMLMaterial) GetStringSlice(path string) ([]string, error)

func (YAMLMaterial) HasMultipleDocuments

func (m YAMLMaterial) HasMultipleDocuments() bool

func (YAMLMaterial) JSONContents

func (m YAMLMaterial) JSONContents() []byte

func (YAMLMaterial) Path

func (m YAMLMaterial) Path() string

Jump to

Keyboard shortcuts

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