-
Notifications
You must be signed in to change notification settings - Fork 5
/
schema.go
104 lines (94 loc) · 2.72 KB
/
schema.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package builtin
import "github.com/tzmfreedom/land/ast"
var schemaSObjectType *ast.ClassType
var describeSObjectResultType *ast.ClassType
func init() {
schema := ast.CreateClass(
"Schema",
nil,
nil,
&ast.MethodMap{
Data: map[string][]*ast.Method{
"getGlobalDescribe": {
&ast.Method{
Name: "getGlobalDescribe",
Modifiers: []*ast.Modifier{ast.PublicModifier()},
Parameters: []*ast.Parameter{},
ReturnType: CreateMapType(StringType, schemaSObjectType),
NativeFunction: func(this *ast.Object, parameter []*ast.Object, extra map[string]interface{}) interface{} {
mapType := CreateMapType(StringType, schemaSObjectType)
newObj := ast.CreateObject(mapType)
values := map[string]*ast.Object{}
for name, _ := range sObjects {
valueObj := ast.CreateObject(schemaSObjectType)
valueObj.Extra["type"] = name
values[name] = valueObj
}
newObj.Extra["values"] = values
return newObj
},
},
},
},
},
)
primitiveClassMap.Set("Schema", schema)
classMap := ast.NewClassMap()
schemaSObjectType = ast.CreateClass(
"SObjectType",
nil,
nil,
&ast.MethodMap{
Data: map[string][]*ast.Method{
"getDescribe": {
&ast.Method{
Name: "getDescribe",
Modifiers: []*ast.Modifier{ast.PublicModifier()},
Parameters: []*ast.Parameter{},
ReturnType: describeSObjectResultType,
NativeFunction: func(this *ast.Object, parameter []*ast.Object, extra map[string]interface{}) interface{} {
sObj := sObjects[this.Extra["type"].(string)]
obj := ast.CreateObject(describeSObjectResultType)
obj.Extra["info"] = sObj
return obj
},
},
},
"newSObject": {
&ast.Method{
Name: "newSObject",
Modifiers: []*ast.Modifier{ast.PublicModifier()},
Parameters: []*ast.Parameter{},
ReturnType: SObjectType,
NativeFunction: func(this *ast.Object, parameter []*ast.Object, extra map[string]interface{}) interface{} {
typeName := this.Extra["type"].(string)
classType, ok := PrimitiveClassMap().Get(typeName)
if !ok {
panic("not found")
}
return ast.CreateObject(classType)
},
},
},
},
},
)
classMap.Set("SObjectType", schemaSObjectType)
describeSObjectResultType = ast.CreateClass(
"DescribeSObjectResult",
nil,
&ast.MethodMap{
Data: map[string][]*ast.Method{},
},
ast.NewMethodMap(),
)
classMap.Set("DescribeSObjectResult", describeSObjectResultType)
sObjectTypeFields := ast.CreateClass(
"SObjectTypeFields",
nil,
ast.NewMethodMap(),
ast.NewMethodMap(),
)
classMap.Set("SObjectTypeFields", sObjectTypeFields)
nameSpaceStore.Set("Schema", classMap)
}