@nestia/core 12.0.0-dev.20260601.1 → 12.0.0-dev.20260612.2
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/LICENSE +21 -21
- package/MIGRATION.md +169 -169
- package/README.md +93 -93
- package/lib/adaptors/McpAdaptor.d.ts +75 -0
- package/lib/adaptors/McpAdaptor.js +257 -0
- package/lib/adaptors/McpAdaptor.js.map +1 -0
- package/lib/adaptors/WebSocketAdaptor.js +4 -4
- package/lib/adaptors/WebSocketAdaptor.js.map +1 -1
- package/lib/decorators/McpRoute.d.ts +69 -0
- package/lib/decorators/McpRoute.js +58 -0
- package/lib/decorators/McpRoute.js.map +1 -0
- package/lib/decorators/TypedParam.js +4 -4
- package/lib/decorators/TypedParam.js.map +1 -1
- package/lib/decorators/TypedRoute.js +1 -1
- package/lib/decorators/TypedRoute.js.map +1 -1
- package/lib/decorators/internal/IMcpRouteReflect.d.ts +2 -0
- package/lib/decorators/internal/IMcpRouteReflect.js +3 -0
- package/lib/decorators/internal/IMcpRouteReflect.js.map +1 -0
- package/lib/decorators/internal/get_path_and_querify.js +4 -4
- package/lib/decorators/internal/get_path_and_querify.js.map +1 -1
- package/lib/decorators/internal/get_path_and_stringify.js +4 -4
- package/lib/decorators/internal/get_path_and_stringify.js.map +1 -1
- package/lib/decorators/internal/load_controller.js +34 -65
- package/lib/decorators/internal/load_controller.js.map +1 -1
- package/lib/decorators/internal/validate_request_body.js +4 -4
- package/lib/decorators/internal/validate_request_body.js.map +1 -1
- package/lib/decorators/internal/validate_request_form_data.js +4 -4
- package/lib/decorators/internal/validate_request_form_data.js.map +1 -1
- package/lib/decorators/internal/validate_request_headers.js +4 -4
- package/lib/decorators/internal/validate_request_headers.js.map +1 -1
- package/lib/decorators/internal/validate_request_query.js +4 -4
- package/lib/decorators/internal/validate_request_query.js.map +1 -1
- package/lib/module.d.ts +2 -0
- package/lib/module.js +2 -0
- package/lib/module.js.map +1 -1
- package/native/cmd/ttsc-nestia/main.go +11 -11
- package/native/go.mod +32 -32
- package/native/go.sum +54 -54
- package/native/plugin/plan.go +102 -102
- package/native/transform/ast.go +32 -32
- package/native/transform/build.go +380 -444
- package/native/transform/cleanup.go +408 -408
- package/native/transform/contributor.go +97 -68
- package/native/transform/core_querify.go +231 -227
- package/native/transform/core_transform.go +1996 -1713
- package/native/transform/core_websocket.go +115 -115
- package/native/transform/exports.go +13 -13
- package/native/transform/mcp_transform.go +414 -0
- package/native/transform/node_transform.go +357 -0
- package/native/transform/path_rewrite.go +285 -285
- package/native/transform/printer.go +244 -244
- package/native/transform/rewrite.go +668 -662
- package/native/transform/run.go +73 -73
- package/native/transform/transform.go +336 -403
- package/native/transform/typia_fast.go +352 -326
- package/native/transform/typia_replacement.go +24 -24
- package/native/transform.cjs +43 -43
- package/package.json +15 -8
- package/src/adaptors/McpAdaptor.ts +276 -0
- package/src/adaptors/WebSocketAdaptor.ts +429 -429
- package/src/decorators/DynamicModule.ts +44 -44
- package/src/decorators/EncryptedBody.ts +97 -97
- package/src/decorators/EncryptedController.ts +40 -40
- package/src/decorators/EncryptedModule.ts +98 -98
- package/src/decorators/EncryptedRoute.ts +213 -213
- package/src/decorators/HumanRoute.ts +21 -21
- package/src/decorators/McpRoute.ts +154 -0
- package/src/decorators/NoTransformConfigurationError.ts +40 -40
- package/src/decorators/PlainBody.ts +76 -76
- package/src/decorators/SwaggerCustomizer.ts +97 -97
- package/src/decorators/SwaggerExample.ts +180 -180
- package/src/decorators/TypedBody.ts +57 -57
- package/src/decorators/TypedException.ts +147 -147
- package/src/decorators/TypedFormData.ts +187 -187
- package/src/decorators/TypedHeaders.ts +66 -66
- package/src/decorators/TypedParam.ts +77 -77
- package/src/decorators/TypedQuery.ts +234 -234
- package/src/decorators/TypedRoute.ts +198 -196
- package/src/decorators/WebSocketRoute.ts +242 -242
- package/src/decorators/doNotThrowTransformError.ts +5 -5
- package/src/decorators/internal/EncryptedConstant.ts +2 -2
- package/src/decorators/internal/IMcpRouteReflect.ts +40 -0
- package/src/decorators/internal/IWebSocketRouteReflect.ts +23 -23
- package/src/decorators/internal/get_path_and_querify.ts +94 -94
- package/src/decorators/internal/get_path_and_stringify.ts +110 -110
- package/src/decorators/internal/get_text_body.ts +16 -16
- package/src/decorators/internal/headers_to_object.ts +11 -11
- package/src/decorators/internal/is_request_body_undefined.ts +12 -12
- package/src/decorators/internal/load_controller.ts +91 -76
- package/src/decorators/internal/route_error.ts +43 -43
- package/src/decorators/internal/validate_request_body.ts +64 -64
- package/src/decorators/internal/validate_request_form_data.ts +67 -67
- package/src/decorators/internal/validate_request_headers.ts +76 -76
- package/src/decorators/internal/validate_request_query.ts +83 -83
- package/src/index.ts +5 -5
- package/src/module.ts +25 -23
- package/src/options/IRequestBodyValidator.ts +20 -20
- package/src/options/IRequestFormDataProps.ts +27 -27
- package/src/options/IRequestHeadersValidator.ts +22 -22
- package/src/options/IRequestQueryValidator.ts +20 -20
- package/src/options/IResponseBodyQuerifier.ts +25 -25
- package/src/options/IResponseBodyStringifier.ts +30 -30
- package/src/transform.ts +101 -101
- package/src/typings/Creator.ts +3 -3
- package/src/typings/get-function-location.d.ts +7 -7
- package/src/utils/ArrayUtil.ts +7 -7
- package/src/utils/ExceptionManager.ts +115 -115
- package/src/utils/Singleton.ts +16 -16
- package/src/utils/SourceFinder.ts +54 -54
- package/src/utils/VersioningStrategy.ts +27 -27
- package/native/transform/cleanup_test.go +0 -76
- package/native/transform/commonjs_import_alias_test.go +0 -49
- package/native/transform/core_dispatch_test.go +0 -127
- package/native/transform/path_rewrite_test.go +0 -243
- package/native/transform/rewrite_test.go +0 -118
- package/native/transform/rewrite_unique_base_test.go +0 -48
|
@@ -1,326 +1,352 @@
|
|
|
1
|
-
package transform
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"path/filepath"
|
|
5
|
-
"strings"
|
|
6
|
-
|
|
7
|
-
shimast "github.com/microsoft/typescript-go/shim/ast"
|
|
8
|
-
shimchecker "github.com/microsoft/typescript-go/shim/checker"
|
|
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
|
-
if
|
|
50
|
-
if
|
|
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
|
-
name
|
|
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
|
-
func
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
return
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
return
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
if
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
if
|
|
302
|
-
|
|
303
|
-
}
|
|
304
|
-
name
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
|
|
1
|
+
package transform
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"path/filepath"
|
|
5
|
+
"strings"
|
|
6
|
+
|
|
7
|
+
shimast "github.com/microsoft/typescript-go/shim/ast"
|
|
8
|
+
shimchecker "github.com/microsoft/typescript-go/shim/checker"
|
|
9
|
+
shimprinter "github.com/microsoft/typescript-go/shim/printer"
|
|
10
|
+
"github.com/samchon/ttsc/packages/ttsc/driver"
|
|
11
|
+
typiaadapter "github.com/samchon/typia/packages/typia/native/adapter"
|
|
12
|
+
nativecontext "github.com/samchon/typia/packages/typia/native/core/context"
|
|
13
|
+
nativetransform "github.com/samchon/typia/packages/typia/native/transform"
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
// nestiaTypiaNodeTransform wraps typia's per-file AST transformer as a ttsc
|
|
17
|
+
// PluginTransform. typia owns its call-site detection and (in ec mode) injects
|
|
18
|
+
// the namespace imports tsgo's module-transform aliases, so @nestia/core simply
|
|
19
|
+
// runs it alongside its own decorator transform inside the same emit pipeline.
|
|
20
|
+
// A recovered typia transform error is reported as a diagnostic.
|
|
21
|
+
func nestiaTypiaNodeTransform(
|
|
22
|
+
prog *driver.Program,
|
|
23
|
+
pluginOptions typiaadapter.PluginOptions,
|
|
24
|
+
addDiagnostic func(Diagnostic),
|
|
25
|
+
) driver.PluginTransform {
|
|
26
|
+
transformOptions := pluginOptions.TransformOptions()
|
|
27
|
+
extras := nativecontext.ITypiaContext_Extras{
|
|
28
|
+
AddDiagnostic: func(diag *shimast.Diagnostic) int {
|
|
29
|
+
addDiagnostic(Diagnostic{Code: "typia.transform", Message: "typia transform error"})
|
|
30
|
+
return 1
|
|
31
|
+
},
|
|
32
|
+
}
|
|
33
|
+
return func(ec *shimprinter.EmitContext, sf *shimast.SourceFile) *shimast.SourceFile {
|
|
34
|
+
return nativetransform.Transform(prog, &transformOptions, extras, ec)(sf)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
type nestiaTypiaImportRoot struct {
|
|
39
|
+
module string
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
func collectNestiaTypiaCallSites(files []*shimast.SourceFile, checker *shimchecker.Checker) []typiaadapter.CallSite {
|
|
43
|
+
sites := []typiaadapter.CallSite{}
|
|
44
|
+
for _, file := range files {
|
|
45
|
+
if file == nil || file.IsDeclarationFile {
|
|
46
|
+
continue
|
|
47
|
+
}
|
|
48
|
+
roots, fallback := nestiaTypiaImportRoots(file)
|
|
49
|
+
if len(roots) == 0 {
|
|
50
|
+
if fallback {
|
|
51
|
+
sites = append(sites, typiaadapter.CollectCallSites([]*shimast.SourceFile{file}, checker)...)
|
|
52
|
+
}
|
|
53
|
+
continue
|
|
54
|
+
}
|
|
55
|
+
file.ForEachChild(func(node *shimast.Node) bool {
|
|
56
|
+
visitNestiaTypiaCallSite(file, checker, roots, node, &sites)
|
|
57
|
+
return false
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
return sites
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
func visitNestiaTypiaCallSite(
|
|
64
|
+
file *shimast.SourceFile,
|
|
65
|
+
checker *shimchecker.Checker,
|
|
66
|
+
roots map[string]nestiaTypiaImportRoot,
|
|
67
|
+
node *shimast.Node,
|
|
68
|
+
sites *[]typiaadapter.CallSite,
|
|
69
|
+
) {
|
|
70
|
+
if node == nil {
|
|
71
|
+
return
|
|
72
|
+
}
|
|
73
|
+
if node.Kind == shimast.KindCallExpression {
|
|
74
|
+
call := node.AsCallExpression()
|
|
75
|
+
if call != nil && nestiaTypiaCallLooksPossible(call, roots) {
|
|
76
|
+
if site, ok := tryNestiaTypiaCallSite(file, checker, node); ok {
|
|
77
|
+
*sites = append(*sites, site)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
node.ForEachChild(func(child *shimast.Node) bool {
|
|
82
|
+
visitNestiaTypiaCallSite(file, checker, roots, child, sites)
|
|
83
|
+
return false
|
|
84
|
+
})
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
func nestiaTypiaImportRoots(file *shimast.SourceFile) (map[string]nestiaTypiaImportRoot, bool) {
|
|
88
|
+
roots := map[string]nestiaTypiaImportRoot{}
|
|
89
|
+
fallback := false
|
|
90
|
+
if file == nil || file.Statements == nil {
|
|
91
|
+
return roots, fallback
|
|
92
|
+
}
|
|
93
|
+
for _, stmt := range file.Statements.Nodes {
|
|
94
|
+
if stmt == nil || stmt.Kind != shimast.KindImportDeclaration {
|
|
95
|
+
continue
|
|
96
|
+
}
|
|
97
|
+
decl := stmt.AsImportDeclaration()
|
|
98
|
+
if decl == nil || decl.ImportClause == nil || decl.ModuleSpecifier == nil || decl.ModuleSpecifier.Kind != shimast.KindStringLiteral {
|
|
99
|
+
continue
|
|
100
|
+
}
|
|
101
|
+
moduleText := decl.ModuleSpecifier.Text()
|
|
102
|
+
module, ok := nestiaTypiaImportModule(moduleText)
|
|
103
|
+
if ok == false {
|
|
104
|
+
continue
|
|
105
|
+
}
|
|
106
|
+
clause := decl.ImportClause.AsImportClause()
|
|
107
|
+
if clause == nil || clause.PhaseModifier == shimast.KindTypeKeyword {
|
|
108
|
+
continue
|
|
109
|
+
}
|
|
110
|
+
if name := clause.Name(); name != nil {
|
|
111
|
+
roots[name.Text()] = nestiaTypiaImportRoot{module: module}
|
|
112
|
+
}
|
|
113
|
+
if clause.NamedBindings == nil {
|
|
114
|
+
continue
|
|
115
|
+
}
|
|
116
|
+
if clause.NamedBindings.Kind == shimast.KindNamespaceImport {
|
|
117
|
+
if name := clause.NamedBindings.Name(); name != nil {
|
|
118
|
+
roots[name.Text()] = nestiaTypiaImportRoot{module: module}
|
|
119
|
+
}
|
|
120
|
+
continue
|
|
121
|
+
}
|
|
122
|
+
if clause.NamedBindings.Kind != shimast.KindNamedImports {
|
|
123
|
+
continue
|
|
124
|
+
}
|
|
125
|
+
named := clause.NamedBindings.AsNamedImports()
|
|
126
|
+
if named == nil || named.Elements == nil {
|
|
127
|
+
continue
|
|
128
|
+
}
|
|
129
|
+
for _, elem := range named.Elements.Nodes {
|
|
130
|
+
if elem == nil {
|
|
131
|
+
continue
|
|
132
|
+
}
|
|
133
|
+
spec := elem.AsImportSpecifier()
|
|
134
|
+
if spec == nil || spec.IsTypeOnly {
|
|
135
|
+
continue
|
|
136
|
+
}
|
|
137
|
+
name := spec.Name()
|
|
138
|
+
if name == nil {
|
|
139
|
+
continue
|
|
140
|
+
}
|
|
141
|
+
imported := name.Text()
|
|
142
|
+
if spec.PropertyName != nil {
|
|
143
|
+
imported = spec.PropertyName.Text()
|
|
144
|
+
}
|
|
145
|
+
if module == "" {
|
|
146
|
+
if nestiaTypiaKnownModule(imported) == false {
|
|
147
|
+
continue
|
|
148
|
+
}
|
|
149
|
+
roots[name.Text()] = nestiaTypiaImportRoot{module: imported}
|
|
150
|
+
} else {
|
|
151
|
+
roots[name.Text()] = nestiaTypiaImportRoot{module: module}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return roots, fallback
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
func nestiaTypiaImportModule(specifier string) (string, bool) {
|
|
159
|
+
switch specifier {
|
|
160
|
+
case "typia":
|
|
161
|
+
return "", true
|
|
162
|
+
}
|
|
163
|
+
for _, prefix := range []string{"typia/lib/", "typia/src/"} {
|
|
164
|
+
if strings.HasPrefix(specifier, prefix) {
|
|
165
|
+
name := strings.TrimPrefix(specifier, prefix)
|
|
166
|
+
if strings.Contains(name, "/") || nestiaTypiaKnownModule(name) == false {
|
|
167
|
+
return "", false
|
|
168
|
+
}
|
|
169
|
+
return name, true
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return "", false
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
func nestiaTypiaKnownModule(name string) bool {
|
|
176
|
+
switch name {
|
|
177
|
+
case "functional", "http", "json", "llm", "misc", "module", "notations", "protobuf", "reflect":
|
|
178
|
+
return true
|
|
179
|
+
default:
|
|
180
|
+
return false
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
func nestiaTypiaCallLooksPossible(call *shimast.CallExpression, roots map[string]nestiaTypiaImportRoot) bool {
|
|
185
|
+
root, parts, ok := nestiaTypiaCallSegments(call)
|
|
186
|
+
if ok == false {
|
|
187
|
+
return false
|
|
188
|
+
}
|
|
189
|
+
info, ok := roots[root]
|
|
190
|
+
if ok == false || len(parts) == 0 {
|
|
191
|
+
return false
|
|
192
|
+
}
|
|
193
|
+
if info.module != "" {
|
|
194
|
+
return true
|
|
195
|
+
}
|
|
196
|
+
if len(parts) == 1 {
|
|
197
|
+
return true
|
|
198
|
+
}
|
|
199
|
+
return nestiaTypiaKnownModule(parts[0])
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
func nestiaTypiaCallSegments(call *shimast.CallExpression) (string, []string, bool) {
|
|
203
|
+
if call == nil {
|
|
204
|
+
return "", nil, false
|
|
205
|
+
}
|
|
206
|
+
expression := call.Expression
|
|
207
|
+
parts := []string{}
|
|
208
|
+
for expression != nil && expression.Kind == shimast.KindPropertyAccessExpression {
|
|
209
|
+
property := expression.AsPropertyAccessExpression()
|
|
210
|
+
if property == nil {
|
|
211
|
+
return "", nil, false
|
|
212
|
+
}
|
|
213
|
+
name := property.Name()
|
|
214
|
+
if name == nil || name.Kind != shimast.KindIdentifier {
|
|
215
|
+
return "", nil, false
|
|
216
|
+
}
|
|
217
|
+
id := name.AsIdentifier()
|
|
218
|
+
if id == nil || id.Text == "" {
|
|
219
|
+
return "", nil, false
|
|
220
|
+
}
|
|
221
|
+
parts = append([]string{id.Text}, parts...)
|
|
222
|
+
expression = property.Expression
|
|
223
|
+
}
|
|
224
|
+
if expression == nil || expression.Kind != shimast.KindIdentifier {
|
|
225
|
+
return "", nil, false
|
|
226
|
+
}
|
|
227
|
+
root := expression.AsIdentifier()
|
|
228
|
+
if root == nil || root.Text == "" {
|
|
229
|
+
return "", nil, false
|
|
230
|
+
}
|
|
231
|
+
return root.Text, parts, true
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
func tryNestiaTypiaCallSite(file *shimast.SourceFile, checker *shimchecker.Checker, node *shimast.Node) (typiaadapter.CallSite, bool) {
|
|
235
|
+
if checker == nil {
|
|
236
|
+
return typiaadapter.CallSite{}, false
|
|
237
|
+
}
|
|
238
|
+
call := node.AsCallExpression()
|
|
239
|
+
if call == nil {
|
|
240
|
+
return typiaadapter.CallSite{}, false
|
|
241
|
+
}
|
|
242
|
+
signature := checker.GetResolvedSignature(node)
|
|
243
|
+
if signature == nil {
|
|
244
|
+
return typiaadapter.CallSite{}, false
|
|
245
|
+
}
|
|
246
|
+
declaration := signature.Declaration()
|
|
247
|
+
if declaration == nil {
|
|
248
|
+
return typiaadapter.CallSite{}, false
|
|
249
|
+
}
|
|
250
|
+
sourceFile := shimast.GetSourceFileOfNode(declaration)
|
|
251
|
+
if sourceFile == nil {
|
|
252
|
+
return typiaadapter.CallSite{}, false
|
|
253
|
+
}
|
|
254
|
+
module, ok := nestiaTypiaMatchModule(sourceFile.FileName())
|
|
255
|
+
if !ok {
|
|
256
|
+
return typiaadapter.CallSite{}, false
|
|
257
|
+
}
|
|
258
|
+
method := nestiaTypiaCallSiteMethodName(checker, declaration, call)
|
|
259
|
+
if method == "" {
|
|
260
|
+
return typiaadapter.CallSite{}, false
|
|
261
|
+
}
|
|
262
|
+
root, namespaces, ok := nestiaTypiaExtractRootAndNamespaces(call, method)
|
|
263
|
+
if !ok {
|
|
264
|
+
return typiaadapter.CallSite{}, false
|
|
265
|
+
}
|
|
266
|
+
return typiaadapter.CallSite{
|
|
267
|
+
File: file,
|
|
268
|
+
FilePath: file.FileName(),
|
|
269
|
+
Module: module,
|
|
270
|
+
Method: method,
|
|
271
|
+
Call: call,
|
|
272
|
+
RootName: root,
|
|
273
|
+
Namespaces: namespaces,
|
|
274
|
+
}, true
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
func nestiaTypiaMatchModule(location string) (string, bool) {
|
|
278
|
+
location = filepath.ToSlash(location)
|
|
279
|
+
for _, suffix := range []string{".d.ts", ".ts"} {
|
|
280
|
+
for _, middle := range []string{"typia/lib/", "typia/src/", "packages/typia/src/"} {
|
|
281
|
+
index := strings.LastIndex(location, middle)
|
|
282
|
+
if index < 0 {
|
|
283
|
+
continue
|
|
284
|
+
}
|
|
285
|
+
name := location[index+len(middle):]
|
|
286
|
+
if !strings.HasSuffix(name, suffix) {
|
|
287
|
+
continue
|
|
288
|
+
}
|
|
289
|
+
name = strings.TrimSuffix(name, suffix)
|
|
290
|
+
if strings.Contains(name, "/") {
|
|
291
|
+
continue
|
|
292
|
+
}
|
|
293
|
+
return name, true
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return "", false
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
func nestiaTypiaCallSiteMethodName(checker *shimchecker.Checker, declaration *shimast.Node, call *shimast.CallExpression) string {
|
|
300
|
+
if name := declaration.Name(); name != nil {
|
|
301
|
+
if symbol := checker.GetSymbolAtLocation(name); symbol != nil && symbol.Name != "" {
|
|
302
|
+
return symbol.Name
|
|
303
|
+
}
|
|
304
|
+
if name.Kind == shimast.KindIdentifier {
|
|
305
|
+
if id := name.AsIdentifier(); id != nil {
|
|
306
|
+
return id.Text
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
if call.Expression != nil && call.Expression.Kind == shimast.KindPropertyAccessExpression {
|
|
311
|
+
if property := call.Expression.AsPropertyAccessExpression(); property != nil {
|
|
312
|
+
if name := property.Name(); name != nil && name.Kind == shimast.KindIdentifier {
|
|
313
|
+
if id := name.AsIdentifier(); id != nil {
|
|
314
|
+
return id.Text
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
return ""
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
func nestiaTypiaExtractRootAndNamespaces(call *shimast.CallExpression, method string) (string, []string, bool) {
|
|
323
|
+
expression := call.Expression
|
|
324
|
+
segments := []string{}
|
|
325
|
+
for expression != nil && expression.Kind == shimast.KindPropertyAccessExpression {
|
|
326
|
+
property := expression.AsPropertyAccessExpression()
|
|
327
|
+
if property == nil {
|
|
328
|
+
break
|
|
329
|
+
}
|
|
330
|
+
name := property.Name()
|
|
331
|
+
if name == nil || name.Kind != shimast.KindIdentifier {
|
|
332
|
+
return "", nil, false
|
|
333
|
+
}
|
|
334
|
+
id := name.AsIdentifier()
|
|
335
|
+
if id == nil || id.Text == "" {
|
|
336
|
+
return "", nil, false
|
|
337
|
+
}
|
|
338
|
+
segments = append([]string{id.Text}, segments...)
|
|
339
|
+
expression = property.Expression
|
|
340
|
+
}
|
|
341
|
+
if expression == nil || expression.Kind != shimast.KindIdentifier {
|
|
342
|
+
return "", nil, false
|
|
343
|
+
}
|
|
344
|
+
root := expression.AsIdentifier()
|
|
345
|
+
if root == nil || root.Text == "" || len(segments) == 0 {
|
|
346
|
+
return "", nil, false
|
|
347
|
+
}
|
|
348
|
+
if segments[len(segments)-1] != method {
|
|
349
|
+
return "", nil, false
|
|
350
|
+
}
|
|
351
|
+
return root.Text, segments[:len(segments)-1], true
|
|
352
|
+
}
|