refactor(schema)!: rename Schema -> TypeSet and other small renamings (#21446)

This commit is contained in:
Aaron Craelius
2024-08-30 17:01:48 +00:00
committed by GitHub
parent b33ed0716b
commit ce8f9d40f2
22 changed files with 106 additions and 89 deletions
+12 -10
View File
@@ -11,9 +11,9 @@ type ModuleSchema struct {
types map[string]Type
}
// NewModuleSchema constructs a new ModuleSchema and validates it. Any module schema returned without an error
// is guaranteed to be valid.
func NewModuleSchema(types ...Type) (ModuleSchema, error) {
// CompileModuleSchema compiles the types into a ModuleSchema and validates it.
// Any module schema returned without an error is guaranteed to be valid.
func CompileModuleSchema(types ...Type) (ModuleSchema, error) {
typeMap := map[string]Type{}
for _, typ := range types {
@@ -34,10 +34,10 @@ func NewModuleSchema(types ...Type) (ModuleSchema, error) {
return res, nil
}
// MustNewModuleSchema constructs a new ModuleSchema and panics if it is invalid.
// MustCompileModuleSchema constructs a new ModuleSchema and panics if it is invalid.
// This should only be used in test code or static initialization where it is safe to panic!
func MustNewModuleSchema(types ...Type) ModuleSchema {
sch, err := NewModuleSchema(types...)
func MustCompileModuleSchema(types ...Type) ModuleSchema {
sch, err := CompileModuleSchema(types...)
if err != nil {
panic(err)
}
@@ -79,7 +79,7 @@ func (s ModuleSchema) LookupType(name string) (Type, bool) {
// Types calls the provided function for each type in the module schema and stops if the function returns false.
// The types are iterated over in sorted order by name. This function is compatible with go 1.23 iterators.
func (s ModuleSchema) Types(f func(Type) bool) {
func (s ModuleSchema) AllTypes(f func(Type) bool) {
keys := make([]string, 0, len(s.types))
for k := range s.types {
keys = append(keys, k)
@@ -94,7 +94,7 @@ func (s ModuleSchema) Types(f func(Type) bool) {
// ObjectTypes iterators over all the object types in the schema in alphabetical order.
func (s ModuleSchema) ObjectTypes(f func(ObjectType) bool) {
s.Types(func(t Type) bool {
s.AllTypes(func(t Type) bool {
objTyp, ok := t.(ObjectType)
if ok {
return f(objTyp)
@@ -105,7 +105,7 @@ func (s ModuleSchema) ObjectTypes(f func(ObjectType) bool) {
// EnumTypes iterators over all the enum types in the schema in alphabetical order.
func (s ModuleSchema) EnumTypes(f func(EnumType) bool) {
s.Types(func(t Type) bool {
s.AllTypes(func(t Type) bool {
enumType, ok := t.(EnumType)
if ok {
return f(enumType)
@@ -169,4 +169,6 @@ func (s *ModuleSchema) UnmarshalJSON(data []byte) error {
return nil
}
var _ Schema = ModuleSchema{}
func (ModuleSchema) isTypeSet() {}
var _ TypeSet = ModuleSchema{}