@zyno-io/ts-reflection 26.803.2224
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +966 -0
- package/dist/reflection/annotations.d.ts +15 -0
- package/dist/reflection/annotations.d.ts.map +1 -0
- package/dist/reflection/compact-metadata.d.ts +18 -0
- package/dist/reflection/compact-metadata.d.ts.map +1 -0
- package/dist/reflection/conversion.d.ts +15 -0
- package/dist/reflection/conversion.d.ts.map +1 -0
- package/dist/reflection/deserializer.d.ts +15 -0
- package/dist/reflection/deserializer.d.ts.map +1 -0
- package/dist/reflection/errors.d.ts +8 -0
- package/dist/reflection/errors.d.ts.map +1 -0
- package/dist/reflection/index.d.ts +10 -0
- package/dist/reflection/index.d.ts.map +1 -0
- package/dist/reflection/metadata-store.d.ts +20 -0
- package/dist/reflection/metadata-store.d.ts.map +1 -0
- package/dist/reflection/model.d.ts +273 -0
- package/dist/reflection/model.d.ts.map +1 -0
- package/dist/reflection/primitive-conversion.d.ts +2 -0
- package/dist/reflection/primitive-conversion.d.ts.map +1 -0
- package/dist/reflection/reflection-class.d.ts +60 -0
- package/dist/reflection/reflection-class.d.ts.map +1 -0
- package/dist/reflection/type-utils.d.ts +34 -0
- package/dist/reflection/type-utils.d.ts.map +1 -0
- package/dist/type-compiler/download-prebuilt.cjs +114 -0
- package/dist/type-compiler/go/ast_expression.go +187 -0
- package/dist/type-compiler/go/ast_metadata.go +388 -0
- package/dist/type-compiler/go/collect.go +963 -0
- package/dist/type-compiler/go/compact_metadata.go +553 -0
- package/dist/type-compiler/go/emission_plan.go +340 -0
- package/dist/type-compiler/go/emit_ast.go +557 -0
- package/dist/type-compiler/go/emit_ast_test.go +558 -0
- package/dist/type-compiler/go/go.mod +10 -0
- package/dist/type-compiler/go/plugin.go +359 -0
- package/dist/type-compiler/go/plugin_test.go +1206 -0
- package/dist/type-compiler/go/precompute.go +86 -0
- package/dist/type-compiler/go/receive_type.go +912 -0
- package/dist/type-compiler/go/resolve.go +265 -0
- package/dist/type-compiler/go/source_scan.go +51 -0
- package/dist/type-compiler/go/text_parse.go +734 -0
- package/dist/type-compiler/go/type_expr.go +1291 -0
- package/dist/type-compiler/go/typia_expr.go +2316 -0
- package/dist/type-compiler/index.cjs +43 -0
- package/dist/type-compiler/pnp.cjs +474 -0
- package/dist/type-compiler/prebuilt.cjs +324 -0
- package/dist/type-metadata-runtime.cjs +1 -0
- package/dist/type-metadata-runtime.d.ts +2 -0
- package/dist/type-metadata-runtime.d.ts.map +1 -0
- package/dist/type-metadata-runtime.js +107 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/primitives.d.ts +33 -0
- package/dist/types/primitives.d.ts.map +1 -0
- package/dist/types/runtime.d.ts +2 -0
- package/dist/types/runtime.d.ts.map +1 -0
- package/dist/types/type-annotations.d.ts +28 -0
- package/dist/types/type-annotations.d.ts.map +1 -0
- package/package.json +47 -0
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
package main
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"sort"
|
|
5
|
+
"strings"
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
func collectFlags(info *fileInfo, reg *registry, raw string) map[string]string {
|
|
9
|
+
flags := map[string]string{}
|
|
10
|
+
for _, part := range splitTop(raw, "&") {
|
|
11
|
+
part = strings.TrimSpace(part)
|
|
12
|
+
name, args, isGeneric := generic(part)
|
|
13
|
+
if !isGeneric {
|
|
14
|
+
name = part
|
|
15
|
+
}
|
|
16
|
+
switch name {
|
|
17
|
+
case "PrimaryKey":
|
|
18
|
+
flags["primaryKey"] = "true"
|
|
19
|
+
case "AutoIncrement":
|
|
20
|
+
flags["autoIncrement"] = "true"
|
|
21
|
+
case "Reference":
|
|
22
|
+
flags["reference"] = plainValue(firstOptionArg(args))
|
|
23
|
+
case "Index":
|
|
24
|
+
flags["index"] = plainValue(firstOptionArg(args))
|
|
25
|
+
case "Indexed":
|
|
26
|
+
flags["index"] = plainValue(optionArg(args, 1))
|
|
27
|
+
case "Unique":
|
|
28
|
+
flags["unique"] = plainValue(firstOptionArg(args))
|
|
29
|
+
default:
|
|
30
|
+
if alias, owner, ok := resolveAlias(info, reg, name); ok && alias.body != raw {
|
|
31
|
+
for key, value := range collectFlags(owner, reg, alias.body) {
|
|
32
|
+
flags[key] = value
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return flags
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
func resolveAlias(info *fileInfo, reg *registry, name string) (aliasInfo, *fileInfo, bool) {
|
|
41
|
+
alias, owner, _, ok := resolveAliasRef(info, reg, name)
|
|
42
|
+
return alias, owner, ok
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
func resolveAliasRef(info *fileInfo, reg *registry, name string) (aliasInfo, *fileInfo, *importRef, bool) {
|
|
46
|
+
if alias, ok := info.aliases[name]; ok {
|
|
47
|
+
return alias, info, nil, true
|
|
48
|
+
}
|
|
49
|
+
if ref, ok := info.imports[name]; ok {
|
|
50
|
+
if target := reg.byPath[ref.source]; target != nil {
|
|
51
|
+
alias, owner, ownerName, ok := resolveExportedAlias(target, reg, ref.exportName, map[string]bool{})
|
|
52
|
+
if ok {
|
|
53
|
+
ownerRef := importRef{
|
|
54
|
+
source: owner.moduleKey,
|
|
55
|
+
exportName: ownerName,
|
|
56
|
+
spec: moduleSpecifierForFiles(info, owner),
|
|
57
|
+
}
|
|
58
|
+
return alias, owner, &ownerRef, true
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return aliasInfo{}, nil, nil, false
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
func resolveInterface(info *fileInfo, reg *registry, name string) (string, *fileInfo, bool) {
|
|
66
|
+
body, owner, _, ok := resolveInterfaceRefAt(info, reg, name, 0)
|
|
67
|
+
return body, owner, ok
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
func resolveInterfaceRef(info *fileInfo, reg *registry, name string) (string, *fileInfo, *importRef, bool) {
|
|
71
|
+
return resolveInterfaceRefAt(info, reg, name, 0)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
func resolveInterfaceRefAt(info *fileInfo, reg *registry, name string, pos int) (string, *fileInfo, *importRef, bool) {
|
|
75
|
+
decl, owner, ref, ok := resolveInterfaceDeclRefAt(info, reg, name, pos)
|
|
76
|
+
if !ok {
|
|
77
|
+
return "", nil, nil, false
|
|
78
|
+
}
|
|
79
|
+
return interfaceFullBody(owner, reg, decl, map[string]bool{}), owner, ref, true
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
func resolveInterfaceDeclRefAt(info *fileInfo, reg *registry, name string, pos int) (interfaceInfo, *fileInfo, *importRef, bool) {
|
|
83
|
+
name = interfaceRefName(name)
|
|
84
|
+
if decl, ok := chooseInterface(info, name, pos); ok {
|
|
85
|
+
return decl, info, nil, true
|
|
86
|
+
}
|
|
87
|
+
if ref, ok := info.imports[name]; ok {
|
|
88
|
+
if target := reg.byPath[ref.source]; target != nil {
|
|
89
|
+
decl, owner, ownerName, ok := resolveExportedInterfaceDecl(target, reg, ref.exportName, map[string]bool{})
|
|
90
|
+
if ok {
|
|
91
|
+
ownerRef := importRef{
|
|
92
|
+
source: owner.moduleKey,
|
|
93
|
+
exportName: ownerName,
|
|
94
|
+
spec: moduleSpecifierForFiles(info, owner),
|
|
95
|
+
}
|
|
96
|
+
return decl, owner, &ownerRef, true
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return interfaceInfo{}, nil, nil, false
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
func resolveEnum(info *fileInfo, reg *registry, name string) (enumInfo, *fileInfo, bool) {
|
|
104
|
+
if enum, ok := info.enums[name]; ok {
|
|
105
|
+
return enum, info, true
|
|
106
|
+
}
|
|
107
|
+
if ref, ok := info.imports[name]; ok {
|
|
108
|
+
if target := reg.byPath[ref.source]; target != nil {
|
|
109
|
+
enum, owner, _, ok := resolveExportedEnum(target, reg, ref.exportName, map[string]bool{})
|
|
110
|
+
if ok {
|
|
111
|
+
return enum, owner, true
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return enumInfo{}, nil, false
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
func chooseInterface(info *fileInfo, name string, pos int) (interfaceInfo, bool) {
|
|
119
|
+
decls := info.interfaces[name]
|
|
120
|
+
if len(decls) == 0 {
|
|
121
|
+
return interfaceInfo{}, false
|
|
122
|
+
}
|
|
123
|
+
sort.SliceStable(decls, func(i, j int) bool { return decls[i].pos < decls[j].pos })
|
|
124
|
+
if pos > 0 {
|
|
125
|
+
for i := len(decls) - 1; i >= 0; i-- {
|
|
126
|
+
if decls[i].pos <= pos {
|
|
127
|
+
return decls[i], true
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return decls[len(decls)-1], true
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
func chooseClass(info *fileInfo, name string, pos int) (*classInfo, bool) {
|
|
135
|
+
decls := []*classInfo{}
|
|
136
|
+
for _, class := range info.classes {
|
|
137
|
+
if class.name == name {
|
|
138
|
+
decls = append(decls, class)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if len(decls) == 0 {
|
|
142
|
+
return nil, false
|
|
143
|
+
}
|
|
144
|
+
sort.SliceStable(decls, func(i, j int) bool { return decls[i].pos < decls[j].pos })
|
|
145
|
+
if pos > 0 {
|
|
146
|
+
for i := len(decls) - 1; i >= 0; i-- {
|
|
147
|
+
if decls[i].pos <= pos {
|
|
148
|
+
return decls[i], true
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return nil, false
|
|
152
|
+
}
|
|
153
|
+
return decls[len(decls)-1], true
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
func resolveClassRefAt(info *fileInfo, reg *registry, name string, pos int) (*classInfo, *fileInfo, bool) {
|
|
157
|
+
name = interfaceRefName(name)
|
|
158
|
+
if class, ok := chooseClass(info, name, pos); ok {
|
|
159
|
+
return class, info, true
|
|
160
|
+
}
|
|
161
|
+
if ref, ok := info.imports[name]; ok {
|
|
162
|
+
if target := reg.byPath[ref.source]; target != nil {
|
|
163
|
+
if class, ok := chooseClass(target, ref.exportName, 0); ok {
|
|
164
|
+
return class, target, true
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return nil, nil, false
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
func resolveExportedAlias(info *fileInfo, reg *registry, name string, seen map[string]bool) (aliasInfo, *fileInfo, string, bool) {
|
|
172
|
+
key := info.moduleKey + "\x00" + name
|
|
173
|
+
if seen[key] {
|
|
174
|
+
return aliasInfo{}, nil, "", false
|
|
175
|
+
}
|
|
176
|
+
seen[key] = true
|
|
177
|
+
if alias, ok := info.aliases[name]; ok {
|
|
178
|
+
return alias, info, name, true
|
|
179
|
+
}
|
|
180
|
+
if ref, ok := info.reexports[name]; ok {
|
|
181
|
+
if target := reg.byPath[ref.source]; target != nil {
|
|
182
|
+
if alias, owner, ownerName, ok := resolveExportedAlias(target, reg, ref.exportName, seen); ok {
|
|
183
|
+
return alias, owner, ownerName, true
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
for _, ref := range info.exportStar {
|
|
188
|
+
if target := reg.byPath[ref.source]; target != nil {
|
|
189
|
+
if alias, owner, ownerName, ok := resolveExportedAlias(target, reg, name, seen); ok {
|
|
190
|
+
return alias, owner, ownerName, true
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return aliasInfo{}, nil, "", false
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
func resolveExportedInterface(info *fileInfo, reg *registry, name string, seen map[string]bool) (string, *fileInfo, string, bool) {
|
|
198
|
+
decl, owner, ownerName, ok := resolveExportedInterfaceDecl(info, reg, name, seen)
|
|
199
|
+
if !ok {
|
|
200
|
+
return "", nil, "", false
|
|
201
|
+
}
|
|
202
|
+
return interfaceFullBody(owner, reg, decl, map[string]bool{}), owner, ownerName, true
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
func moduleSpecifierForFiles(from *fileInfo, to *fileInfo) string {
|
|
206
|
+
if from != nil && from.file != nil && to != nil && to.file != nil {
|
|
207
|
+
return moduleSpecifier(from.file.FileName(), to.file.FileName())
|
|
208
|
+
}
|
|
209
|
+
if to != nil {
|
|
210
|
+
return to.moduleKey
|
|
211
|
+
}
|
|
212
|
+
return ""
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
func resolveExportedInterfaceDecl(info *fileInfo, reg *registry, name string, seen map[string]bool) (interfaceInfo, *fileInfo, string, bool) {
|
|
216
|
+
key := info.moduleKey + "\x00" + name
|
|
217
|
+
if seen[key] {
|
|
218
|
+
return interfaceInfo{}, nil, "", false
|
|
219
|
+
}
|
|
220
|
+
seen[key] = true
|
|
221
|
+
if decl, ok := chooseInterface(info, name, 0); ok {
|
|
222
|
+
return decl, info, name, true
|
|
223
|
+
}
|
|
224
|
+
if ref, ok := info.reexports[name]; ok {
|
|
225
|
+
if target := reg.byPath[ref.source]; target != nil {
|
|
226
|
+
if decl, owner, ownerName, ok := resolveExportedInterfaceDecl(target, reg, ref.exportName, seen); ok {
|
|
227
|
+
return decl, owner, ownerName, true
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
for _, ref := range info.exportStar {
|
|
232
|
+
if target := reg.byPath[ref.source]; target != nil {
|
|
233
|
+
if decl, owner, ownerName, ok := resolveExportedInterfaceDecl(target, reg, name, seen); ok {
|
|
234
|
+
return decl, owner, ownerName, true
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return interfaceInfo{}, nil, "", false
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
func resolveExportedEnum(info *fileInfo, reg *registry, name string, seen map[string]bool) (enumInfo, *fileInfo, string, bool) {
|
|
242
|
+
key := info.moduleKey + "\x00" + name
|
|
243
|
+
if seen[key] {
|
|
244
|
+
return enumInfo{}, nil, "", false
|
|
245
|
+
}
|
|
246
|
+
seen[key] = true
|
|
247
|
+
if enum, ok := info.enums[name]; ok {
|
|
248
|
+
return enum, info, name, true
|
|
249
|
+
}
|
|
250
|
+
if ref, ok := info.reexports[name]; ok {
|
|
251
|
+
if target := reg.byPath[ref.source]; target != nil {
|
|
252
|
+
if enum, owner, ownerName, ok := resolveExportedEnum(target, reg, ref.exportName, seen); ok {
|
|
253
|
+
return enum, owner, ownerName, true
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
for _, ref := range info.exportStar {
|
|
258
|
+
if target := reg.byPath[ref.source]; target != nil {
|
|
259
|
+
if enum, owner, ownerName, ok := resolveExportedEnum(target, reg, name, seen); ok {
|
|
260
|
+
return enum, owner, ownerName, true
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return enumInfo{}, nil, "", false
|
|
265
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
package main
|
|
2
|
+
|
|
3
|
+
func isCodePosition(text string, pos int) bool {
|
|
4
|
+
quote := byte(0)
|
|
5
|
+
lineComment := false
|
|
6
|
+
blockComment := false
|
|
7
|
+
for i := 0; i < pos && i < len(text); i++ {
|
|
8
|
+
current := text[i]
|
|
9
|
+
next := byte(0)
|
|
10
|
+
if i+1 < len(text) {
|
|
11
|
+
next = text[i+1]
|
|
12
|
+
}
|
|
13
|
+
if lineComment {
|
|
14
|
+
if current == '\n' || current == '\r' {
|
|
15
|
+
lineComment = false
|
|
16
|
+
}
|
|
17
|
+
continue
|
|
18
|
+
}
|
|
19
|
+
if blockComment {
|
|
20
|
+
if current == '*' && next == '/' {
|
|
21
|
+
blockComment = false
|
|
22
|
+
i++
|
|
23
|
+
}
|
|
24
|
+
continue
|
|
25
|
+
}
|
|
26
|
+
if quote != 0 {
|
|
27
|
+
if current == '\\' {
|
|
28
|
+
i++
|
|
29
|
+
continue
|
|
30
|
+
}
|
|
31
|
+
if current == quote {
|
|
32
|
+
quote = 0
|
|
33
|
+
}
|
|
34
|
+
continue
|
|
35
|
+
}
|
|
36
|
+
if current == '/' && next == '/' {
|
|
37
|
+
lineComment = true
|
|
38
|
+
i++
|
|
39
|
+
continue
|
|
40
|
+
}
|
|
41
|
+
if current == '/' && next == '*' {
|
|
42
|
+
blockComment = true
|
|
43
|
+
i++
|
|
44
|
+
continue
|
|
45
|
+
}
|
|
46
|
+
if current == '\'' || current == '"' || current == '`' {
|
|
47
|
+
quote = current
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return quote == 0 && !lineComment && !blockComment
|
|
51
|
+
}
|