Finish native completion and retire legacy command machinery
This commit is contained in:
@@ -1,11 +1,8 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// effectivePipelineProjection safely materializes configuration for persistence
|
||||
@@ -78,11 +75,6 @@ type effectiveScriptoriumConfig struct {
|
||||
Artifacts map[string]ScriptoriumArtifactConfig `yaml:"artifacts" json:"artifacts"`
|
||||
}
|
||||
|
||||
type projectedPipelineValue struct {
|
||||
record EffectivePipelineValueRecord
|
||||
segments []string
|
||||
}
|
||||
|
||||
func projectEffectivePipeline(cfg *PipelineConfig) effectivePipelineProjection {
|
||||
projection := effectivePipelineProjection{
|
||||
Workspace: cfg.Workspace, Campaigns: cfg.Campaigns, Storage: effectiveStorageConfig{Backend: cfg.Storage.Backend},
|
||||
@@ -118,65 +110,3 @@ func projectionJSON(projection effectivePipelineProjection) ([]byte, error) {
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func projectionValueTree(value any) (any, error) {
|
||||
data, err := json.Marshal(value)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("encode typed pipeline projection: %w", err)
|
||||
}
|
||||
decoder := json.NewDecoder(bytes.NewReader(data))
|
||||
decoder.UseNumber()
|
||||
var root any
|
||||
if err := decoder.Decode(&root); err != nil {
|
||||
return nil, fmt.Errorf("decode effective pipeline projection: %w", err)
|
||||
}
|
||||
return root, nil
|
||||
}
|
||||
|
||||
func projectionValueRecords(projection effectivePipelineProjection) ([]EffectivePipelineValueRecord, error) {
|
||||
detailed, err := projectionDetailedRecords(projection)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
records := make([]EffectivePipelineValueRecord, 0, len(detailed))
|
||||
for _, value := range detailed {
|
||||
records = append(records, value.record)
|
||||
}
|
||||
return records, nil
|
||||
}
|
||||
|
||||
func projectionDetailedRecords(value any) ([]projectedPipelineValue, error) {
|
||||
decoded, err := projectionValueTree(value)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
root, ok := decoded.(map[string]any)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("effective pipeline projection must be a mapping")
|
||||
}
|
||||
var records []projectedPipelineValue
|
||||
appendProjectionRecords(&records, nil, root)
|
||||
sort.Slice(records, func(i, j int) bool { return records[i].record.Path < records[j].record.Path })
|
||||
return records, nil
|
||||
}
|
||||
|
||||
func appendProjectionRecords(records *[]projectedPipelineValue, segments []string, value any) {
|
||||
if mapping, ok := value.(map[string]any); ok && len(mapping) > 0 {
|
||||
keys := make([]string, 0, len(mapping))
|
||||
for key := range mapping {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
for _, key := range keys {
|
||||
child := append(append([]string(nil), segments...), key)
|
||||
appendProjectionRecords(records, child, mapping[key])
|
||||
}
|
||||
return
|
||||
}
|
||||
encoded, _ := json.Marshal(value)
|
||||
path := strings.Join(segments, ".")
|
||||
*records = append(*records, projectedPipelineValue{
|
||||
record: EffectivePipelineValueRecord{Path: path, Value: string(encoded)},
|
||||
segments: append([]string(nil), segments...),
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user