version

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	V1_0_Forge_Preview3 = APIVersion{
		Version:   "1.0.forge-preview.3",
		Minor:     1,
		Patch:     0,
		Codename:  "forge",
		Preview:   3,
		IsPreview: true,
	}

	V1_0_Forge_Preview2 = APIVersion{
		Version:   "1.0.forge-preview.2",
		Minor:     1,
		Patch:     0,
		Codename:  "forge",
		Preview:   2,
		IsPreview: true,
	}

	V1_0_Forge_Preview1 = APIVersion{
		Version:   "1.0.forge-preview.1",
		Minor:     1,
		Patch:     0,
		Codename:  "forge",
		Preview:   1,
		IsPreview: true,
	}

	// Latest is the current/default API version
	Latest = V1_0_Forge_Preview3

	// Supported lists all supported API versions
	Supported = []APIVersion{V1_0_Forge_Preview3, V1_0_Forge_Preview2, V1_0_Forge_Preview1}
)

Defined API versions (newest to oldest)

View Source
var DefaultRegistry = NewTransformerRegistry()

DefaultRegistry is the global transformer registry.

Functions

func ForcedIncludes

func ForcedIncludes(from, to APIVersion, objectType constants.ObjectType) []string

ForcedIncludes collects forced include keys from the default registry.

func IsSupported

func IsSupported(s string) bool

IsSupported returns true if the given version string is supported.

func Register

func Register(t Transformer)

Register adds a transformer to the default registry.

func SupportedVersionStrings

func SupportedVersionStrings() []string

SupportedVersionStrings returns a slice of all supported version strings.

func Transform

func Transform(from, to APIVersion, objectType constants.ObjectType, data map[string]any) map[string]any

Transform applies response transformers from the default registry.

func TransformRequest

func TransformRequest(from, to APIVersion, objectType constants.ObjectType, data map[string]any) map[string]any

TransformRequest applies request transformers from the default registry.

Types

type APIVersion

type APIVersion struct {
	Version   string // Full version string "1.0.forge" or "1.1.forge-preview.1"
	Minor     int    // Minor version number
	Patch     int    // Patch version number
	Codename  string // Version codename (e.g., "forge")
	Preview   int    // Preview number (0 for stable releases)
	IsPreview bool   // True if this is a preview version
}

APIVersion represents an API version with minor, patch, codename, and optional preview. Stable format: <minor>.<patch>.<codename> (e.g., 1.0.forge) Preview format: <minor>.<patch>.<codename>-preview.<n> (e.g., 1.1.forge-preview.1)

func MustParse

func MustParse(s string) APIVersion

MustParse parses a version string and panics if it fails. Use only for known-valid version strings.

func Parse

func Parse(s string) (APIVersion, error)

Parse parses a version string into an APIVersion. Returns an error if the format is invalid or the version is not supported.

func (APIVersion) After

func (v APIVersion) After(other APIVersion) bool

After returns true if v is after other (newer version).

func (APIVersion) Before

func (v APIVersion) Before(other APIVersion) bool

Before returns true if v is before other (older version). Comparison order: minor → patch → codename → preview (preview < stable)

func (APIVersion) Equal

func (v APIVersion) Equal(other APIVersion) bool

Equal returns true if v and other are the same version.

func (APIVersion) String

func (v APIVersion) String() string

String returns the full version string.

type IncludeForcer

type IncludeForcer interface {
	// ForcedIncludes returns include keys (dot-paths relative to the root object type) that must be resolved when downgrading a response of the given object type.
	ForcedIncludes(objectType constants.ObjectType) []string
}

IncludeForcer is an optional interface a Transformer can implement to declare include keys that must be resolved on the latest-version response before the downgrade runs, so the transformer has the data it needs (e.g. expanding `user` so its fields can be hoisted back onto the parent).

type Transformer

type Transformer interface {
	// FromVersion returns the version this transformer applies FROM (newer version)
	FromVersion() APIVersion
	// ToVersion returns the version this transformer applies TO (older version)
	ToVersion() APIVersion
	// ObjectTypes returns the object types this transformer handles
	ObjectTypes() []constants.ObjectType
	// Transform transforms the response data from FromVersion format to ToVersion format (downgrade)
	Transform(objectType constants.ObjectType, data map[string]any) map[string]any
	// TransformRequest transforms the request data from ToVersion format to FromVersion format (upgrade)
	TransformRequest(objectType constants.ObjectType, data map[string]any) map[string]any
}

Transformer defines an interface for transforming requests and responses between API versions. Each transformer handles the conversion between two adjacent versions: - Transform: converts responses from a newer version to an older version (downgrade) - TransformRequest: converts requests from an older version to a newer version (upgrade)

type TransformerRegistry

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

TransformerRegistry manages a collection of version transformers.

func NewTransformerRegistry

func NewTransformerRegistry() *TransformerRegistry

NewTransformerRegistry creates a new empty transformer registry.

func (*TransformerRegistry) ForcedIncludes

func (r *TransformerRegistry) ForcedIncludes(from, to APIVersion, objectType constants.ObjectType) []string

ForcedIncludes collects the include keys required by every transformer that would run when downgrading a response of the given object type from the 'from' version to the 'to' version.

func (*TransformerRegistry) Register

func (r *TransformerRegistry) Register(t Transformer)

Register adds a transformer to the registry.

func (*TransformerRegistry) Transform

func (r *TransformerRegistry) Transform(from, to APIVersion, objectType constants.ObjectType, data map[string]any) map[string]any

Transform applies the chain of transformers needed to convert response data from the 'from' version to the 'to' version for the given object type. Transformers are applied in order from newest to oldest (downgrade).

func (*TransformerRegistry) TransformRequest

func (r *TransformerRegistry) TransformRequest(from, to APIVersion, objectType constants.ObjectType, data map[string]any) map[string]any

TransformRequest applies the chain of transformers needed to convert request data from the 'from' version to the 'to' version for the given object type. This upgrades requests from older versions to the latest format. Transformers are applied in reverse order from oldest to newest (upgrade).

Jump to

Keyboard shortcuts

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