Documentation
¶
Overview ¶
Package valueobjects holds the strongly-typed identifiers and value types shared across flexitype's domain. Every internal identifier is a distinct ULID newtype so aggregates can never be cross-wired at compile time.
Index ¶
- Constants
- type AttributeDefinitionID
- type AttributeValueID
- type DataType
- type Default
- type DependencyID
- type DynamicKind
- type DynamicValue
- type EntityID
- type MediaMeta
- type Quantity
- type RelationshipDefinitionID
- type RelationshipID
- type RelativePeriod
- type Scope
- type TenantID
- type TypeDefinitionID
- type Value
- func NewBoolValue(b bool) Value
- func NewDateTimeValue(t time.Time) Value
- func NewDateValue(t time.Time) Value
- func NewDecimalValue(s string) (Value, error)
- func NewEmailValue(s string) (Value, error)
- func NewEnumValue(s string) Value
- func NewFloatValue(f float64) Value
- func NewIntegerValue(i int64) Value
- func NewJSONValue(raw json.RawMessage) (Value, error)
- func NewMediaValue(raw json.RawMessage) (Value, error)
- func NewQuantityValue(magnitude, unit string, base float64) (Value, error)
- func NewStringValue(s string) Value
- func NewTimeValue(t time.Time) Value
- func NewURLValue(s string) (Value, error)
- func ParseValue(dt DataType, raw json.RawMessage) (Value, error)
- func UnmarshalTypedValue(raw json.RawMessage) (Value, error)
- func (v Value) Bool() bool
- func (v Value) Compare(other Value) (int, error)
- func (v Value) DataType() DataType
- func (v Value) Equal(other Value) bool
- func (v Value) Float() float64
- func (v Value) Int() int64
- func (v Value) IsZero() bool
- func (v Value) JSON() json.RawMessage
- func (v Value) Length() int
- func (v Value) MarshalJSON() ([]byte, error)
- func (v Value) MarshalTyped() (json.RawMessage, error)
- func (v Value) Media() MediaMeta
- func (v Value) Quantity() Quantity
- func (v Value) String() string
- func (v Value) Text() string
- func (v Value) Time() time.Time
Constants ¶
const ( DateFormat = "2006-01-02" TimeFormat = "15:04:05" )
Wire formats for temporal values.
const DefaultTenant = TenantID("default")
DefaultTenant is the tenant used when a caller does not segment data.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AttributeDefinitionID ¶
AttributeDefinitionID identifies an attribute definition.
func MustParseAttributeDefinitionID ¶
func MustParseAttributeDefinitionID(s string) AttributeDefinitionID
MustParseAttributeDefinitionID parses s, panicking on error.
func NewAttributeDefinitionID ¶
func NewAttributeDefinitionID() AttributeDefinitionID
NewAttributeDefinitionID mints a new AttributeDefinitionID.
func ParseAttributeDefinitionID ¶
func ParseAttributeDefinitionID(s string) (AttributeDefinitionID, error)
ParseAttributeDefinitionID parses a string into an AttributeDefinitionID.
func (AttributeDefinitionID) Equals ¶
func (id AttributeDefinitionID) Equals(other AttributeDefinitionID) bool
Equals checks if two AttributeDefinitionIDs are equal.
type AttributeValueID ¶
AttributeValueID identifies a stored attribute value.
func MustParseAttributeValueID ¶
func MustParseAttributeValueID(s string) AttributeValueID
MustParseAttributeValueID parses s, panicking on error.
func NewAttributeValueID ¶
func NewAttributeValueID() AttributeValueID
NewAttributeValueID mints a new AttributeValueID.
func ParseAttributeValueID ¶
func ParseAttributeValueID(s string) (AttributeValueID, error)
ParseAttributeValueID parses a string into an AttributeValueID.
func (AttributeValueID) Equals ¶
func (id AttributeValueID) Equals(other AttributeValueID) bool
Equals checks if two AttributeValueIDs are equal.
type DataType ¶
type DataType string
DataType enumerates the soft types an attribute definition can declare.
const ( DataTypeBool DataType = "bool" DataTypeString DataType = "string" DataTypeInteger DataType = "integer" DataTypeFloat DataType = "float" DataTypeDecimal DataType = "decimal" DataTypeDate DataType = "date" DataTypeTime DataType = "time" DataTypeDateTime DataType = "datetime" DataTypeEnum DataType = "enum" DataTypeURL DataType = "url" DataTypeEmail DataType = "email" DataTypeJSON DataType = "json" // DataTypeMedia stores a reference to a file/image in object storage: // the value is metadata (object key, mime, size, checksum, filename), // never the bytes. DataTypeMedia DataType = "media" // DataTypeQuantity is a magnitude with a unit (10 kg, 250 mm). Values // normalize to a base unit for comparison; the original unit is kept // for display. DataTypeQuantity DataType = "quantity" )
The supported soft data types.
func ParseDataType ¶
ParseDataType validates a data type name.
func (DataType) IsOrdered ¶
IsOrdered reports whether values of this type have a total order and support min/max value and range constraints.
func (DataType) IsTemporal ¶
IsTemporal reports whether values of this type carry a timestamp and support dynamic (relative-time) defaults and conditions.
type Default ¶
type Default struct {
Static *Value
Dynamic *DynamicValue
}
Default declares an attribute's default: either a static typed value or a dynamic one resolved when the default is applied. Exactly one side is set.
func (Default) MarshalJSON ¶
MarshalJSON persists the static side in its self-describing typed form so the default survives storage round-trips.
func (*Default) UnmarshalJSON ¶
UnmarshalJSON is the inverse of MarshalJSON.
type DependencyID ¶
DependencyID identifies an attribute value dependency.
func MustParseDependencyID ¶
func MustParseDependencyID(s string) DependencyID
MustParseDependencyID parses s, panicking on error.
func NewDependencyID ¶
func NewDependencyID() DependencyID
NewDependencyID mints a new DependencyID.
func ParseDependencyID ¶
func ParseDependencyID(s string) (DependencyID, error)
ParseDependencyID parses a string into a DependencyID.
func (DependencyID) Equals ¶
func (id DependencyID) Equals(other DependencyID) bool
Equals checks if two DependencyIDs are equal.
type DynamicKind ¶
type DynamicKind string
DynamicKind enumerates the runtime-computed value kinds.
const ( // DynamicNow resolves to the current instant (datetime attributes). DynamicNow DynamicKind = "now" // DynamicToday resolves to the current date (date attributes). DynamicToday DynamicKind = "today" // DynamicRelative resolves to now offset by Amount * Period. DynamicRelative DynamicKind = "relative_time" )
type DynamicValue ¶
type DynamicValue struct {
Kind DynamicKind `json:"kind"`
Period RelativePeriod `json:"period,omitempty"`
Amount int `json:"amount,omitempty"`
}
DynamicValue is a value computed at evaluation time rather than stored: "now", "today", or "now plus/minus an offset". Used for temporal defaults and dynamic dependency conditions.
func (DynamicValue) Resolve ¶
Resolve computes the concrete Value for the given data type at instant now.
func (DynamicValue) Validate ¶
func (d DynamicValue) Validate(dt DataType) error
Validate checks the dynamic value's shape and its compatibility with the attribute's data type.
type EntityID ¶
type EntityID string
EntityID anchors attribute values to the consumer's own domain object (a product, a part, a user, ...). It is deliberately an opaque string — consumers keep their identifier scheme; ULIDs are recommended.
func ParseEntityID ¶
ParseEntityID validates a consumer entity identifier.
type MediaMeta ¶
type MediaMeta struct {
ObjectKey string `json:"object_key"`
MIME string `json:"mime"`
Size int64 `json:"size"`
Checksum string `json:"checksum,omitempty"`
Filename string `json:"filename,omitempty"`
}
MediaMeta describes a stored file/image. The bytes live in object storage; this metadata is the attribute value.
type Quantity ¶
type Quantity struct {
Magnitude string `json:"magnitude"`
Unit string `json:"unit"`
Base float64 `json:"base"`
}
Quantity is a magnitude with a unit. Base is the magnitude converted to the family's base unit; comparisons and constraints use it, while Magnitude/Unit are kept for display and round-trip.
type RelationshipDefinitionID ¶
RelationshipDefinitionID identifies a relationship definition.
func MustParseRelationshipDefinitionID ¶
func MustParseRelationshipDefinitionID(s string) RelationshipDefinitionID
MustParseRelationshipDefinitionID parses s, panicking on error.
func NewRelationshipDefinitionID ¶
func NewRelationshipDefinitionID() RelationshipDefinitionID
NewRelationshipDefinitionID mints a new RelationshipDefinitionID.
func ParseRelationshipDefinitionID ¶
func ParseRelationshipDefinitionID(s string) (RelationshipDefinitionID, error)
ParseRelationshipDefinitionID parses a string into a RelationshipDefinitionID.
func (RelationshipDefinitionID) Equals ¶
func (id RelationshipDefinitionID) Equals(other RelationshipDefinitionID) bool
Equals checks if two RelationshipDefinitionIDs are equal.
type RelationshipID ¶
RelationshipID identifies one relationship instance (a link).
func MustParseRelationshipID ¶
func MustParseRelationshipID(s string) RelationshipID
MustParseRelationshipID parses s, panicking on error.
func NewRelationshipID ¶
func NewRelationshipID() RelationshipID
NewRelationshipID mints a new RelationshipID.
func ParseRelationshipID ¶
func ParseRelationshipID(s string) (RelationshipID, error)
ParseRelationshipID parses a string into a RelationshipID.
func (RelationshipID) Equals ¶
func (id RelationshipID) Equals(other RelationshipID) bool
Equals checks if two RelationshipIDs are equal.
type RelativePeriod ¶
type RelativePeriod string
RelativePeriod is the unit for DynamicRelative offsets.
const ( PeriodSeconds RelativePeriod = "seconds" PeriodMinutes RelativePeriod = "minutes" PeriodHours RelativePeriod = "hours" PeriodDays RelativePeriod = "days" PeriodWeeks RelativePeriod = "weeks" )
The supported relative periods.
type Scope ¶
type Scope struct {
Locale string `json:"locale,omitempty"`
Channel string `json:"channel,omitempty"`
}
Scope locates a value along optional presentation dimensions: a locale (en_AU, de_DE) and a channel/context (web, print, marketplace). The zero Scope is the base/unscoped value. A value's identity within an entity and attribute is (locale, channel), so one attribute can hold a different value per market and channel.
type TenantID ¶
type TenantID string
TenantID segments all data for multi-tenant deployments. It is a consumer controlled identifier, not a ULID, so hosted tiers can map it onto their own account model.
func ParseTenantID ¶
ParseTenantID validates a tenant identifier. Empty resolves to DefaultTenant.
type TypeDefinitionID ¶
TypeDefinitionID identifies a type definition.
func MustParseTypeDefinitionID ¶
func MustParseTypeDefinitionID(s string) TypeDefinitionID
MustParseTypeDefinitionID parses s, panicking on error.
func NewTypeDefinitionID ¶
func NewTypeDefinitionID() TypeDefinitionID
NewTypeDefinitionID mints a new TypeDefinitionID.
func ParseTypeDefinitionID ¶
func ParseTypeDefinitionID(s string) (TypeDefinitionID, error)
ParseTypeDefinitionID parses a string into a TypeDefinitionID.
func (TypeDefinitionID) Equals ¶
func (id TypeDefinitionID) Equals(other TypeDefinitionID) bool
Equals checks if two TypeDefinitionIDs are equal.
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value is an immutable, strongly-typed attribute value: a tagged union across every DataType. Construct through the typed constructors or ParseValue; the zero Value means "absent".
func NewDateTimeValue ¶
NewDateTimeValue builds a datetime value in UTC.
func NewDateValue ¶
NewDateValue builds a date value; the time-of-day portion is discarded.
func NewDecimalValue ¶
NewDecimalValue builds an arbitrary-precision decimal from its canonical string form, e.g. "1234.560000".
func NewEmailValue ¶
NewEmailValue builds a validated email address value.
func NewEnumValue ¶
NewEnumValue builds an enum member value. Membership of the allowed set is enforced by the attribute definition's OneOf constraint.
func NewJSONValue ¶
func NewJSONValue(raw json.RawMessage) (Value, error)
NewJSONValue builds a JSON document value, stored in compact form.
func NewMediaValue ¶
func NewMediaValue(raw json.RawMessage) (Value, error)
NewMediaValue builds a media value from its metadata JSON. The object key, MIME type and a non-negative size are required — the caller (an upload handler) has already put the bytes in storage.
func NewQuantityValue ¶
NewQuantityValue builds a quantity value. base is the magnitude expressed in the unit family's base unit (the caller resolves the conversion factor from the tenant's unit registry).
func NewTimeValue ¶
NewTimeValue builds a time-of-day value; the date portion is discarded.
func NewURLValue ¶
NewURLValue builds a validated absolute URL value.
func ParseValue ¶
func ParseValue(dt DataType, raw json.RawMessage) (Value, error)
ParseValue decodes a raw JSON scalar into a typed Value according to the declared data type. This is the single entry point for values arriving over the API.
func UnmarshalTypedValue ¶
func UnmarshalTypedValue(raw json.RawMessage) (Value, error)
UnmarshalTypedValue decodes the self-describing form written by MarshalTyped.
func (Value) Equal ¶
Equal reports whether two values have the same type and content. Decimals compare numerically ("1.50" equals "1.5").
func (Value) JSON ¶
func (v Value) JSON() json.RawMessage
JSON returns the raw document payload (json values only).
func (Value) MarshalJSON ¶
MarshalJSON renders the natural JSON form of the value.
func (Value) MarshalTyped ¶
func (v Value) MarshalTyped() (json.RawMessage, error)
MarshalTyped encodes the value with its data type so it can be decoded without external context.
func (Value) Quantity ¶
Quantity decodes the magnitude/unit payload and pairs it with the stored base (quantity values only).