d63a09ea2f
A stack property can refer to other stack types. For example: properties: gateway: type: aws/ec2/internetGateway ... In such cases, we need to validate the property during binding, in addition to binding it to an actual type so that we can later validate callers who are constructing instances of this stack and providing property values that we must typecheck. Note that this binding is subtly different than existing stack type binding. All the name validation, resolution, and so forth are the same. However, notice that in this case we are not actually supplying any property setters. That is, internetGateway is not an "expanded" type, in that we have not processed any of its templates. An analogy might help: this is sort of akin referring to an uninstantiated generic type in a traditional programming language, versus its instantiated form. In this case, certain properties aren't available to us, however we can still use it for type identity, etc.
108 lines
1.8 KiB
Go
108 lines
1.8 KiB
Go
// Copyright 2016 Marapongo, Inc. All rights reserved.
|
|
|
|
package ast
|
|
|
|
import (
|
|
"sort"
|
|
)
|
|
|
|
func StableClusters(cs Clusters) []string {
|
|
sorted := make([]string, 0, len(cs))
|
|
for c := range cs {
|
|
sorted = append(sorted, c)
|
|
}
|
|
sort.Strings(sorted)
|
|
return sorted
|
|
}
|
|
|
|
func StableDependencies(ds Dependencies) []Ref {
|
|
sorted := make(Refs, 0, len(ds))
|
|
for d := range ds {
|
|
sorted = append(sorted, d)
|
|
}
|
|
sort.Sort(sorted)
|
|
return sorted
|
|
}
|
|
|
|
func StableDependencyRefs(refs DependencyRefs) []Ref {
|
|
sorted := make(Refs, 0, len(refs))
|
|
for ref := range refs {
|
|
sorted = append(sorted, ref)
|
|
}
|
|
sort.Sort(sorted)
|
|
return sorted
|
|
}
|
|
|
|
func StableKeys(ps PropertyBag) []string {
|
|
sorted := make([]string, 0, len(ps))
|
|
for p := range ps {
|
|
sorted = append(sorted, p)
|
|
}
|
|
sort.Strings(sorted)
|
|
return sorted
|
|
}
|
|
|
|
func StableProperties(ps Properties) []string {
|
|
sorted := make([]string, 0, len(ps))
|
|
for p := range ps {
|
|
sorted = append(sorted, p)
|
|
}
|
|
sort.Strings(sorted)
|
|
return sorted
|
|
}
|
|
|
|
func StablePropertyBag(ps PropertyBag) []string {
|
|
sorted := make([]string, 0, len(ps))
|
|
for p := range ps {
|
|
sorted = append(sorted, p)
|
|
}
|
|
sort.Strings(sorted)
|
|
return sorted
|
|
}
|
|
|
|
func StableServices(ss ServiceMap) []Name {
|
|
sorted := make(Names, 0, len(ss))
|
|
for s := range ss {
|
|
sorted = append(sorted, s)
|
|
}
|
|
sort.Sort(sorted)
|
|
return sorted
|
|
}
|
|
|
|
func StableUntypedServices(ss UntypedServiceMap) []Name {
|
|
sorted := make(Names, 0, len(ss))
|
|
for s := range ss {
|
|
sorted = append(sorted, s)
|
|
}
|
|
sort.Sort(sorted)
|
|
return sorted
|
|
}
|
|
|
|
type Names []Name
|
|
|
|
func (s Names) Len() int {
|
|
return len(s)
|
|
}
|
|
|
|
func (s Names) Swap(i, j int) {
|
|
s[i], s[j] = s[j], s[i]
|
|
}
|
|
|
|
func (s Names) Less(i, j int) bool {
|
|
return s[i] < s[j]
|
|
}
|
|
|
|
type Refs []Ref
|
|
|
|
func (s Refs) Len() int {
|
|
return len(s)
|
|
}
|
|
|
|
func (s Refs) Swap(i, j int) {
|
|
s[i], s[j] = s[j], s[i]
|
|
}
|
|
|
|
func (s Refs) Less(i, j int) bool {
|
|
return s[i] < s[j]
|
|
}
|