2026-09-29 17:58:15 +00:00
package engine
import "os"
2026-10-14 13:14:06 +00:00
// Input selects one source, its destination, and its independent import policy.
2026-09-29 17:58:15 +00:00
type Input struct {
2026-10-16 15:55:29 +00:00
Source Source
Imports bool
Filesystem * FilesystemContext
Destination Path
2026-10-26 00:18:12 +00:00
PlacementMode PlacementMode
2026-09-29 17:58:15 +00:00
}
// Underlay contains strictly composed contributions at one precedence tier.
type Underlay struct { Inputs [ ] Input }
// LayeredOptions selects lower-priority tiers and final application rules.
type LayeredOptions [ T any ] struct {
Definition Definition [ T ]
2026-10-26 00:10:07 +00:00
ImportDefaults ImportDefaults
2026-10-15 15:24:53 +00:00
SourceVersionMode sourceVersionMode
2026-09-29 17:58:15 +00:00
Underlays [ ] Underlay
Overlay string
OverlayFilesystem * FilesystemContext
Overrides [ ] Override
}
// LoadLayered loads a main input and lower-priority grouped inputs through one
// final decode, resolution, and validation lifecycle.
func LoadLayered [ T any ] ( main Input , secrets SecretBinding , supplied ... LayeredOptions [ T ] ) ( * Loaded [ T ] , error ) {
if len ( supplied ) > 1 {
return nil , ( & diagnosticAccumulator { diagnostics : [ ] Diagnostic { optionDiagnostic ( CodeOptionsInvalid , "LoadLayered accepts at most one options value" ) } } ) . loadError ( )
}
var options LayeredOptions [ T ]
if len ( supplied ) != 0 {
options = supplied [ 0 ]
}
request := loadRequest [ T ] {
2026-10-14 13:14:06 +00:00
main : loadInput {
source : main . Source , imports : main . Imports , filesystem : main . Filesystem ,
2026-10-26 00:18:12 +00:00
destination : main . Destination . clone ( ) , placementMode : main . PlacementMode ,
2026-10-14 13:14:06 +00:00
} ,
2026-10-15 15:24:53 +00:00
definition : options . Definition , sourceVersionMode : options . SourceVersionMode ,
2026-10-26 00:13:34 +00:00
importDefaults : options . ImportDefaults ,
2026-10-15 15:24:53 +00:00
overlay : options . Overlay ,
2026-09-29 17:58:15 +00:00
overlayFilesystem : options . OverlayFilesystem ,
overrides : append ( [ ] Override ( nil ) , options . Overrides ... ) ,
underlays : make ( [ ] loadGroup , len ( options . Underlays ) ) ,
}
for index , underlay := range options . Underlays {
request . underlays [ index ] . inputs = make ( [ ] loadInput , len ( underlay . Inputs ) )
for inputIndex , input := range underlay . Inputs {
request . underlays [ index ] . inputs [ inputIndex ] = loadInput {
source : input . Source , imports : input . Imports , filesystem : input . Filesystem ,
2026-10-26 00:18:12 +00:00
destination : input . Destination . clone ( ) , placementMode : input . PlacementMode ,
2026-09-29 17:58:15 +00:00
}
}
}
return loadGroupedWithSecretLookup ( request , secrets , os . LookupEnv )
}