Refactor toolbox and function handling to support synthetic fields and improve type definitions

This commit is contained in:
2025-04-12 02:20:40 -04:00
parent 2ae583e9f3
commit 3093b988f8
13 changed files with 288 additions and 160 deletions

View File

@@ -25,27 +25,27 @@ func getFromType(t reflect.Type, b basic) Type {
switch t.Kind() {
case reflect.String:
b.DataType = String
b.DataType = TypeString
b.typeName = "string"
return b
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
b.DataType = Integer
b.DataType = TypeInteger
b.typeName = "integer"
return b
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
b.DataType = Integer
b.DataType = TypeInteger
b.typeName = "integer"
return b
case reflect.Float32, reflect.Float64:
b.DataType = Number
b.DataType = TypeNumber
b.typeName = "number"
return b
case reflect.Bool:
b.DataType = Boolean
b.DataType = TypeBoolean
b.typeName = "boolean"
return b
@@ -92,7 +92,7 @@ func getField(f reflect.StructField, index int) Type {
}
}
b.DataType = String
b.DataType = TypeString
b.typeName = "string"
return enum{
basic: b,
@@ -104,15 +104,26 @@ func getField(f reflect.StructField, index int) Type {
return getFromType(t, b)
}
func getObject(t reflect.Type) object {
func getObject(t reflect.Type) Object {
fields := make(map[string]Type, t.NumField())
for i := 0; i < t.NumField(); i++ {
field := t.Field(i)
fields[field.Name] = getField(field, i)
if field.Anonymous {
// if the field is anonymous, we need to get the fields of the anonymous struct
// and add them to the object
anon := getObject(field.Type)
for k, v := range anon.fields {
fields[k] = v
}
continue
} else {
fields[field.Name] = getField(field, i)
}
}
return object{
basic: basic{DataType: Object, typeName: "object"},
return Object{
basic: basic{DataType: TypeObject, typeName: "object"},
fields: fields,
}
}
@@ -120,7 +131,7 @@ func getObject(t reflect.Type) object {
func getArray(t reflect.Type) array {
res := array{
basic: basic{
DataType: Array,
DataType: TypeArray,
typeName: "array",
},
}