-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreflection.go
More file actions
196 lines (168 loc) · 4.53 KB
/
reflection.go
File metadata and controls
196 lines (168 loc) · 4.53 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
package reflect
import (
"github.com/nebtex/hybrids/golang/hybrids"
)
type OmniTypes uint16
const (
Table OmniTypes = iota
Enumeration
Struct
Union
Resource
ExternalResource
Application
)
type UnionTypes uint16
const (
UnionOfResources UnionTypes = iota
UnionOfTables
UnionOfExternalResources
)
//LookupFields ...
type LookupFields interface {
FieldCount() int
FieldByPosition(fn hybrids.FieldNumber) (f FieldContainer, ok bool)
FieldByName(fieldName string) (f FieldContainer, ok bool)
}
//LookupEnumeration ...
type LookupEnumeration interface {
//return camelcase
ByUint8ToString(input uint8) (value string, ok bool)
//return camelcase
ByUint16ToString(input uint16) (value string, ok bool)
//accept snake case or camel case
ByStringToUint8(input string) (value uint8, ok bool)
//accept snake case or camel case
ByStringToUint16(input string) (value uint16, ok bool)
}
//Table ...
type TableContainer interface {
ID() string
Application() ApplicationContainer
Name() string
LookupFields() LookupFields
}
//Resource ...
type ResourceContainer interface {
ID() string
Application() ApplicationContainer
Name() string
Position() uint16
Table() TableContainer
}
//Struct ...
type StructContainer interface {
ID() string
Name() string
Application() ApplicationContainer
LookupFields() LookupFields
}
//Items ...
type ItemsContainer interface {
ValueType() OType
HybridType() hybrids.Types
}
//Field ...
type FieldContainer interface {
//full id of this field, with the version, to allow query the backend
ID() string
Application() ApplicationContainer
//table or struct
Parent() OType
//Otype of the field value
//this return nil when is a scalar or vector scalar unless tha the field is an enumeration enumeration
ValueType() OType
//position of this field in the table
Position() hybrids.FieldNumber
//field name
Name() string
//the underlying data type
HybridType() hybrids.Types
//if is a vector the item type
Items() ItemsContainer
}
//Enumeration ...
type EnumerationContainer interface {
Application() ApplicationContainer
ID() string
Name() string
Lookup() LookupEnumeration
//the underlying data type
HybridType() hybrids.Types
}
//Union ...
type UnionContainer interface {
Application() ApplicationContainer
ID() string
Name() string
ItemsKind() UnionTypes
//total numbers of items in the union
LookupFields() LookupFields
}
//Application ...
type LookupResources interface {
ResourceCount() int
//case insensitive
ResourceByName(name string) (r ResourceContainer, ok bool)
ResourceByPosition(position uint16) (r ResourceContainer, ok bool)
}
//Application ...
type ApplicationContainer interface {
//example omniql.almagest.io/nebtex/omniql
Path() string
//branch, commit ot tag
Version() string
//number of resources
LookupResources() LookupResources
LookupImports() LookupImports
ResourceIDType() hybrids.ResourceIDType
}
//LookupImports ...
type LookupImports interface {
ImportsCount() int
ImportByPosition(position uint16) (e ExternalApplicationContainer, ok bool)
ImportByAlias(alias string) (e ExternalApplicationContainer, ok bool)
}
//OType represent any omniql type
type OType interface {
//Table, Field, Enumeration, etc..
Kind() OmniTypes
//if this is a vector this will return the item type
Enumeration() EnumerationContainer
Table() TableContainer
Struct() StructContainer
Union() UnionContainer
Resource() ResourceContainer
ExternalResource() ExternalResourceContainer
}
//ExternalResourceContainer
type ExternalResourceContainer interface {
ID() string
Application() ExternalApplicationContainer
Name() string
}
//ExternalApplicationContainer
type ExternalApplicationContainer interface {
Path() string
Version() string
Alias() string
UsedResourcesCount() int
UsedResource(pos int) ExternalResourceContainer
}
//go:generate stringer -type=OmniTypes
//go:generate stringer -type=UnionTypes
//go:generate mockery -name=LookupFields
//go:generate mockery -name=LookupEnumeration
//go:generate mockery -name=TableContainer
//go:generate mockery -name=ResourceContainer
//go:generate mockery -name=StructContainer
//go:generate mockery -name=ItemsContainer
//go:generate mockery -name=FieldContainer
//go:generate mockery -name=EnumerationContainer
//go:generate mockery -name=UnionContainer
//go:generate mockery -name=LookupResources
//go:generate mockery -name=ApplicationContainer
//go:generate mockery -name=LookupImports
//go:generate mockery -name=OType
//go:generate mockery -name=ExternalResourceContainer
//go:generate mockery -name=ExternalApplicationContainer