normalize

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package normalize maps provider-family fields onto neutral V2 metering measures. It contains no provider-name branches and performs no pricing.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidMapping = errors.New("metering/normalize: invalid provider mapping")
	ErrInvalidField   = errors.New("metering/normalize: invalid provider field")
)

Functions

This section is empty.

Types

type Field

type Field struct {
	Name    string
	Lexeme  string
	Present bool
	Null    bool
}

Field is one bounded provider source field. Lexeme is retained exactly and parsed without floating point; absent fields never become zero values.

func (Field) Validate

func (f Field) Validate() error

type FieldSpec

type FieldSpec struct {
	Name          string
	EvidencePath  string
	Key           metering.ComponentKey
	Required      bool
	NotApplicable bool
}

FieldSpec binds one provider field to a neutral key. Name is the source field identity used for lookup; EvidencePath is the bounded safe location retained when the field maps to a V2 observation.

type Input

type Input struct {
	Mapping Mapping
	Fields  []Field
}

Input is the pure normalizer input. No request body or provider SDK value is retained; only bounded field identity and economic lexemes are accepted.

type InputMode

type InputMode string

InputMode declares whether a provider's input field is an inclusive total or an already-separated uncached component.

const (
	InputInclusive InputMode = "inclusive_total"
	InputSeparate  InputMode = "separate_components"
)

type Mapping

type Mapping struct {
	ID            string
	Family        string
	Version       string
	InputMode     InputMode
	InputTotal    FieldSpec
	InputUncached FieldSpec
	CacheRead     []FieldSpec
	CacheWrite    []FieldSpec
	Output        FieldSpec
	Reasoning     FieldSpec
	ReasoningMode ReasoningMode
}

Mapping is a versioned provider-family mapping. The mapping is data, not a provider switch in generic metering code.

func (Mapping) Ref

func (m Mapping) Ref() string

Ref is the stable versioned mapping reference retained in result evidence.

func (Mapping) Validate

func (m Mapping) Validate() error

Validate checks mapping identity and field/key consistency without mutating the mapping. Empty optional specs mean the provider declares that dimension not applicable; a configured but absent field remains unknown evidence.

type OriginalField

type OriginalField struct {
	Name         string
	Lexeme       string
	Present      bool
	Null         bool
	EvidencePath string
}

OriginalField is source-qualified evidence retained independently of the normalized measures. It preserves the provider field name and exact lexeme.

type ReasoningMode

type ReasoningMode string

ReasoningMode declares whether reasoning is already contained by the output meter or is an explicitly disjoint output partition.

const (
	ReasoningIncluded ReasoningMode = "included_in_output"
	ReasoningDisjoint ReasoningMode = "disjoint_output_partition"
)

type Result

type Result struct {
	MappingRef     string
	Status         Status
	Measures       []metering.Measure
	Informational  []metering.Measure
	OriginalFields []OriginalField
	Evidence       []metering.SafeEvidenceField
	Diagnostics    []string
}

Result contains disjoint chargeable measures, informational aggregates and source evidence. No monetary amount is calculated here.

func Normalize

func Normalize(input Input) (Result, error)

Normalize converts provider fields according to a versioned mapping. It returns partial/conflict status for unknown or inconsistent partitions while returning an error only for malformed bounded input or mapping contracts.

func (Result) Attach

Attach adds normalized measures/evidence to a caller-supplied V2 envelope. Caller-owned identity, subject and source fields remain authoritative.

type Status

type Status string

Status reports whether the normalized partition is complete. Partial and conflict results are useful bounded evidence and are not silently converted to a zero or an invented residual.

const (
	StatusComplete Status = "complete"
	StatusPartial  Status = "partial"
	StatusConflict Status = "conflict"
)

Jump to

Keyboard shortcuts

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