Documentation
¶
Overview ¶
Package draft owns the targeted replacement semantics introduced by Spec 004.
Index ¶
- Constants
- Variables
- func EnsureSchema(schema Schema) error
- func FormatRevision(revision uint64) string
- func ParseRevision(etag string) (uint64, error)
- func ValidScope(scope string) bool
- type ConfigurationPresence
- type ConflictError
- type Environment
- type Field
- type FieldState
- type FieldValuePresence
- type LayerState
- type Mutation
- type Save
- type Schema
- type SourceProvider
- type SourceSnapshot
- type State
- type Store
- func (s *Store) Mutate(schema Schema, environments []Environment, environmentID string, ...) (View, uint64, error)
- func (s *Store) SaveToSource(schema Schema, environments []Environment, environmentID string, save Save) (View, uint64, error)
- func (s *Store) View(schema Schema, environments []Environment, environmentID string) (View, uint64, error)
- type StructuralError
- type ValidationError
- type View
Constants ¶
View Source
const ( ScopeBaseline = "baseline" ScopeEnvironmentOverride = "environment_override" )
Variables ¶
View Source
var ( ErrEnvironmentNotFound = errors.New("draft environment not found") ErrInvalidScope = errors.New("invalid draft write scope") // ErrSourceRevisionChanged lets a source transaction request the typed // source_revision_mismatch response without coupling draft to an adapter. ErrSourceRevisionChanged = errors.New("source revision changed") )
Functions ¶
func EnsureSchema ¶
func FormatRevision ¶
func ParseRevision ¶
func ValidScope ¶
Types ¶
type ConfigurationPresence ¶
type ConfigurationPresence struct {
Present bool `json:"present"`
Value map[string]any `json:"value,omitempty"`
}
func (ConfigurationPresence) MarshalJSON ¶
func (p ConfigurationPresence) MarshalJSON() ([]byte, error)
MarshalJSON preserves a present null-free empty object while omitting value when the replacement is missing.
type ConflictError ¶
type ConflictError struct {
Code string
CurrentRevision uint64
CurrentSourceRevision string
ConflictScope string
CurrentState View
}
func (*ConflictError) Error ¶
func (e *ConflictError) Error() string
type Environment ¶
type FieldState ¶
type FieldState struct {
Path string `json:"path"`
PackDefault FieldValuePresence `json:"pack_default"`
Baseline FieldValuePresence `json:"baseline"`
DraftBaseline FieldValuePresence `json:"draft_baseline"`
EnvironmentOverride FieldValuePresence `json:"environment_override"`
DraftEnvironmentOverride FieldValuePresence `json:"draft_environment_override"`
Effective FieldValuePresence `json:"effective"`
Origin string `json:"origin"`
EnvironmentOverrideAllowed bool `json:"environment_override_allowed"`
IsEnvironmentOverridden bool `json:"is_environment_overridden"`
SourceRevision string `json:"source_revision"`
Nullable bool `json:"nullable"`
}
type FieldValuePresence ¶
func (FieldValuePresence) MarshalJSON ¶
func (p FieldValuePresence) MarshalJSON() ([]byte, error)
type LayerState ¶
type LayerState struct {
Source ConfigurationPresence `json:"source"`
Draft ConfigurationPresence `json:"draft"`
Resolved ConfigurationPresence `json:"resolved"`
Dirty bool `json:"dirty"`
}
type Mutation ¶
type Mutation struct {
ExpectedRevision uint64
ExpectedSourceRevision string
Scope string
Action string
Configuration json.RawMessage
// Prepare runs under the same lock and source snapshot as precondition
// checks. It lets higher-level resources turn a focused operation into the
// complete replacement required by the draft model.
Prepare func(View) (json.RawMessage, error)
// Validate runs after structural validation and before the replacement is
// committed. Domain services use it for rules outside the Pack structure.
Validate func(map[string]any) error
}
type Save ¶
type Save struct {
ExpectedRevision uint64
ExpectedSourceRevision string
Commit func(SourceSnapshot, State) (SourceSnapshot, error)
}
Save commits the current view's two visible draft replacements to a source. The caller-owned saver executes while the draft lock is held so the source snapshot, preconditions, draft cleanup, and returned view share one observation boundary.
type SourceProvider ¶
type SourceProvider func() (SourceSnapshot, error)
type SourceSnapshot ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
func NewMemory ¶
func NewMemory(source SourceSnapshot, state State) *Store
func Open ¶
func Open(path string, source SourceProvider) (*Store, error)
Open uses .conflow/draft.json only until Spec 005 defines the managed-file format. SourceProvider deliberately remains separate: draft replacements are not a source adapter and must not become the source of truth.
func (*Store) SaveToSource ¶
type StructuralError ¶
type StructuralError struct {
Code string `json:"code"`
Path string `json:"path"`
Scope string `json:"scope"`
Message string `json:"message"`
}
func ValidateReplacement ¶
func ValidateReplacement(schema Schema, scope string, raw json.RawMessage) (map[string]any, []StructuralError)
type ValidationError ¶
type ValidationError struct{ Details []StructuralError }
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
type View ¶
type View struct {
EnvironmentID string `json:"environment_id"`
PackRef string `json:"pack_ref"`
SourceRevision string `json:"source_revision"`
Dirty bool `json:"dirty"`
DirtyScopes []string `json:"dirty_scopes"`
Baseline LayerState `json:"baseline"`
EnvironmentOverride LayerState `json:"environment_override"`
Effective map[string]any `json:"effective"`
FieldStates []FieldState `json:"field_states"`
AffectedEnvironments []Environment `json:"affected_environments"`
}
func BuildView ¶
func BuildView(schema Schema, environments []Environment, source SourceSnapshot, state State, environmentID string) (View, error)
Click to show internal directories.
Click to hide internal directories.