package configkit import ( "io" "go.maximumdirect.net/configkit/internal/engine" ) // Inspection is a reporting view of a frozen load checkpoint, whether the load // succeeded or failed. Its scope filters enumeration; explicit queries and // source records retain their native paths. type Inspection struct{ view engine.InspectionView } // InspectionStage identifies the completed processing represented by a view. // It does not indicate the error location or whether a load succeeded. type InspectionStage string // Inspection checkpoints describe completed processing: main-tier composition, // all source composition, inheritance, decoding, overrides, resolution, and // validation, respectively. The first three retain source trees before typed // defaults. A resolved view does not imply successful secret lookup, identity // checking, or validation. const ( InspectionStageMain InspectionStage = "main" InspectionStageComposed InspectionStage = "composed" InspectionStageInherited InspectionStage = "inherited" InspectionStageDecoded InspectionStage = "decoded" InspectionStageOverridden InspectionStage = "overridden" InspectionStageResolved InspectionStage = "resolved" InspectionStageValidated InspectionStage = "validated" ) // Stage returns the represented checkpoint, or an empty string for a zero view. func (i Inspection) Stage() InspectionStage { switch i.view.Stage() { case engine.InspectionStageMain: return InspectionStageMain case engine.InspectionStageComposed: return InspectionStageComposed case engine.InspectionStageInherited: return InspectionStageInherited case engine.InspectionStageDecoded: return InspectionStageDecoded case engine.InspectionStageOverridden: return InspectionStageOverridden case engine.InspectionStageResolved: return InspectionStageResolved case engine.InspectionStageValidated: return InspectionStageValidated default: return "" } } // InspectSubtree selects a canonical JSON Pointer reporting location, including // an absent location. Equivalent key and index spellings select the same scope. // Nil, manually constructed results and invalid paths cannot produce a view. func (r *Result[T]) InspectSubtree(path Path) (Inspection, bool) { if r == nil { return Inspection{}, false } view, ok := engine.NewInspectionView(r.inspection, toEnginePath(path)) return Inspection{view: view}, ok } // InspectSubtree selects a canonical JSON Pointer reporting location from a // failed load's available frozen snapshot. Equivalent key and index spellings // select the same scope; an absent location is valid. Nil or zero errors, // unavailable snapshots, and invalid paths cannot produce a view. func (e *LoadError) InspectSubtree(path Path) (Inspection, bool) { if e == nil || e.value == nil { return Inspection{}, false } view, ok := engine.NewInspectionView(e.value.Inspection(), toEnginePath(path)) return Inspection{view: view}, ok } // Metadata returns the unfiltered metadata of the represented checkpoint. func (i Inspection) Metadata() Metadata { return Metadata{value: i.view.Inspection().Metadata()} } // HistoricalPaths returns observed paths at or beneath the reporting scope. func (i Inspection) HistoricalPaths() []Path { values := i.view.HistoricalPaths() paths := make([]Path, len(values)) for index := range values { paths[index] = fromEnginePath(values[index]) } return paths } // WriteEffective renders the saved value at the reporting scope with its // original sensitivity. Unavailable values and nil writers return an error; // writer errors can leave partial output. func (i Inspection) WriteEffective(output io.Writer) error { return i.view.WriteEffective(output) } // Diff compares frozen views at the same canonical scope, including differences // at an ancestor when the existing comparison treats that ancestor atomically. // Views may come from different root Go types. Unavailable or mismatched views // return an error without records. Comparison is independent of checkpoint and // load outcome and does not compare diagnostics. func (i Inspection) Diff(other Inspection) ([]Difference, error) { values, err := i.view.Diff(other.view) if err != nil { return nil, err } return fromEngineDifferences(values), nil } // Sources returns the full detached source catalog. func (i Inspection) Sources() []SourceInfo { values := i.view.Inspection().Sources() if values == nil { return nil } result := make([]SourceInfo, len(values)) for index := range values { result[index] = fromEngineSourceInfo(values[index]) } return result } // Source returns a detached record from the full source catalog. func (i Inspection) Source(id string) (SourceInfo, bool) { value, ok := i.view.Inspection().Source(id) return fromEngineSourceInfo(value), ok } // SourceContext returns the borrowed resource context for an acquired source. func (i Inspection) SourceContext(id string) (ResourceContext, bool) { value, ok := i.view.Inspection().SourceContext(id) return ResourceContext{FS: value.FS, BaseDir: value.BaseDir}, ok } // Explain queries a native path, whether or not it lies within the scope. func (i Inspection) Explain(path Path) (Explanation, bool) { value, ok := i.view.Inspection().Explain(toEnginePath(path)) return fromEngineExplanation(value), ok } // WriteExplanation renders an explicit native path using the frozen load. func (i Inspection) WriteExplanation(output io.Writer, path Path) error { return i.view.Inspection().WriteExplanation(output, toEnginePath(path)) }