@nestia/core 12.0.0-rc.4 → 12.1.0

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.
Files changed (60) hide show
  1. package/lib/adaptors/McpAdaptor.js +21 -18
  2. package/lib/adaptors/McpAdaptor.js.map +1 -1
  3. package/lib/decorators/EncryptedBody.js +2 -7
  4. package/lib/decorators/EncryptedBody.js.map +1 -1
  5. package/lib/decorators/EncryptedRoute.js +1 -1
  6. package/lib/decorators/EncryptedRoute.js.map +1 -1
  7. package/lib/decorators/McpRoute.js +1 -1
  8. package/lib/decorators/McpRoute.js.map +1 -1
  9. package/lib/decorators/NoTransformConfigurationError.js +2 -2
  10. package/lib/decorators/PlainBody.js +2 -7
  11. package/lib/decorators/PlainBody.js.map +1 -1
  12. package/lib/decorators/SwaggerCustomizer.js +2 -2
  13. package/lib/decorators/SwaggerCustomizer.js.map +1 -1
  14. package/lib/decorators/SwaggerExample.d.ts +37 -40
  15. package/lib/decorators/SwaggerExample.js +24 -26
  16. package/lib/decorators/SwaggerExample.js.map +1 -1
  17. package/lib/decorators/TypedBody.js +3 -7
  18. package/lib/decorators/TypedBody.js.map +1 -1
  19. package/lib/decorators/TypedException.d.ts +2 -2
  20. package/lib/decorators/TypedFormData.js +2 -7
  21. package/lib/decorators/TypedFormData.js.map +1 -1
  22. package/lib/decorators/TypedQuery.js +2 -9
  23. package/lib/decorators/TypedQuery.js.map +1 -1
  24. package/lib/decorators/WebSocketRoute.js +1 -1
  25. package/lib/decorators/WebSocketRoute.js.map +1 -1
  26. package/lib/decorators/internal/get_path_and_querify.js +1 -1
  27. package/lib/decorators/internal/get_path_and_querify.js.map +1 -1
  28. package/lib/decorators/internal/is_media_type.d.ts +1 -0
  29. package/lib/decorators/internal/is_media_type.js +11 -0
  30. package/lib/decorators/internal/is_media_type.js.map +1 -0
  31. package/lib/decorators/internal/validate_request_query.js.map +1 -1
  32. package/native/plugin/plan.go +17 -0
  33. package/native/transform/build.go +39 -80
  34. package/native/transform/contributor.go +4 -64
  35. package/native/transform/core_transform.go +42 -705
  36. package/native/transform/node_transform.go +3 -5
  37. package/native/transform/printer.go +0 -217
  38. package/native/transform/transform.go +2 -91
  39. package/native/transform/typia_fast.go +0 -320
  40. package/package.json +10 -10
  41. package/src/adaptors/McpAdaptor.ts +29 -21
  42. package/src/decorators/EncryptedBody.ts +2 -9
  43. package/src/decorators/EncryptedRoute.ts +1 -1
  44. package/src/decorators/McpRoute.ts +6 -5
  45. package/src/decorators/NoTransformConfigurationError.ts +2 -2
  46. package/src/decorators/PlainBody.ts +2 -9
  47. package/src/decorators/SwaggerCustomizer.ts +8 -2
  48. package/src/decorators/SwaggerExample.ts +43 -45
  49. package/src/decorators/TypedBody.ts +5 -9
  50. package/src/decorators/TypedException.ts +2 -2
  51. package/src/decorators/TypedFormData.ts +7 -9
  52. package/src/decorators/TypedQuery.ts +7 -12
  53. package/src/decorators/WebSocketRoute.ts +1 -1
  54. package/src/decorators/internal/get_path_and_querify.ts +1 -1
  55. package/src/decorators/internal/is_media_type.ts +10 -0
  56. package/src/decorators/internal/validate_request_query.ts +2 -1
  57. package/native/transform/cleanup.go +0 -408
  58. package/native/transform/exports.go +0 -13
  59. package/native/transform/rewrite.go +0 -668
  60. package/native/transform/typia_replacement.go +0 -24
@@ -15,8 +15,7 @@ import (
15
15
  // runtime references resolve to namespace imports tsgo's module-transform
16
16
  // aliases), injects those imports, and normalizes the synthetic operator tokens
17
17
  // typia's programmers leave nil. A diagnostic is appended for any site whose
18
- // generation raises a (recovered) transform error, matching the legacy text
19
- // path's swallow-and-report behavior.
18
+ // generation raises a (recovered) transform error.
20
19
  //
21
20
  // addDiagnostic receives one entry per failed site; the build command turns a
22
21
  // non-empty diagnostic slice into a non-zero exit.
@@ -97,8 +96,7 @@ func nestiaCoreNodeTransform(
97
96
  result = nestiaCoreInjectImports(result, importer.ToStatements(), ec)
98
97
  // The node path prints through tsgo's printer, which dereferences the
99
98
  // conditional ?/: operator tokens typia's programmers leave nil; the
100
- // legacy text path filled them via normalizeNestiaSyntheticTokens before
101
- // printing, so do the same here.
99
+ // so normalizeNestiaSyntheticTokens fills them before printing.
102
100
  normalizeNestiaSyntheticTokens(result.AsNode())
103
101
  return result
104
102
  }
@@ -211,7 +209,7 @@ func nestiaCoreCollectMethodReplacements(
211
209
  }
212
210
  // @WebSocketRoute carries no injected validator (it is not a method kind),
213
211
  // but its acceptor/driver parameter shapes are validated here, mirroring the
214
- // legacy visitNestiaCoreNode path. Validate against the parse-tree method so
212
+ // collection pass. Validate against the parse-tree method so
215
213
  // parameter type text resolves even when typia rebuilt this method.
216
214
  if len(canonical) != 0 && canonical[len(canonical)-1] == "WebSocketRoute" {
217
215
  for _, diag := range validateNestiaCoreWebSocketRoute(state.prog, context, nestiaCoreOriginalNode(state.ec, node), call, canonical) {
@@ -2,227 +2,10 @@ package transform
2
2
 
3
3
  import (
4
4
  shimast "github.com/microsoft/typescript-go/shim/ast"
5
- shimprinter "github.com/microsoft/typescript-go/shim/printer"
6
5
  )
7
6
 
8
7
  const nestiaKindColonToken = shimast.KindQuestionToken + 1
9
8
 
10
- func emitNestiaWithIdentifierSubstitutions(
11
- node *shimast.Node,
12
- sourceFile *shimast.SourceFile,
13
- substitutions map[string]string,
14
- ) string {
15
- node = stripNestiaTypeSyntax(node)
16
- node = rewriteNestiaIdentifiers(node, substitutions)
17
- normalizeNestiaSyntheticTokens(node)
18
- return emitNestiaNode(node, sourceFile)
19
- }
20
-
21
- func emitNestiaPreservingTypesWithIdentifierSubstitutions(
22
- node *shimast.Node,
23
- sourceFile *shimast.SourceFile,
24
- substitutions map[string]string,
25
- ) string {
26
- node = rewriteNestiaIdentifiers(node, substitutions)
27
- normalizeNestiaSyntheticTokens(node)
28
- return emitNestiaNode(node, sourceFile)
29
- }
30
-
31
- func emitNestiaNode(node *shimast.Node, sourceFile *shimast.SourceFile) string {
32
- return shimprinter.NewPrinter(shimprinter.PrinterOptions{
33
- RemoveComments: true,
34
- NewLine: 2,
35
- }, shimprinter.PrintHandlers{}, nil).Emit(node, sourceFile)
36
- }
37
-
38
- func stripNestiaTypeSyntax(node *shimast.Node) *shimast.Node {
39
- if node == nil {
40
- return nil
41
- }
42
- factory := shimast.NewNodeFactory(shimast.NodeFactoryHooks{})
43
- var visitor *shimast.NodeVisitor
44
- visitor = shimast.NewNodeVisitor(func(current *shimast.Node) *shimast.Node {
45
- if current == nil {
46
- return nil
47
- }
48
- switch current.Kind {
49
- case shimast.KindAsExpression, shimast.KindSatisfiesExpression, shimast.KindTypeAssertionExpression, shimast.KindNonNullExpression:
50
- return visitor.VisitNode(current.Expression())
51
- case shimast.KindVariableDeclaration:
52
- decl := current.AsVariableDeclaration()
53
- return factory.UpdateVariableDeclaration(
54
- decl,
55
- visitor.VisitNode(decl.Name()),
56
- nil,
57
- nil,
58
- visitor.VisitNode(decl.Initializer),
59
- )
60
- case shimast.KindParameter:
61
- parameter := current.AsParameterDeclaration()
62
- return factory.UpdateParameterDeclaration(
63
- parameter,
64
- visitor.VisitModifiers(parameter.Modifiers()),
65
- visitor.VisitNode(parameter.DotDotDotToken),
66
- visitor.VisitNode(parameter.Name()),
67
- nil,
68
- nil,
69
- visitor.VisitNode(parameter.Initializer),
70
- )
71
- case shimast.KindArrowFunction:
72
- arrow := current.AsArrowFunction()
73
- return factory.UpdateArrowFunction(
74
- arrow,
75
- visitor.VisitModifiers(arrow.Modifiers()),
76
- nil,
77
- visitor.VisitNodes(arrow.Parameters),
78
- nil,
79
- nil,
80
- visitor.VisitNode(arrow.EqualsGreaterThanToken),
81
- visitor.VisitNode(arrow.Body),
82
- )
83
- case shimast.KindCallExpression:
84
- call := current.AsCallExpression()
85
- return factory.UpdateCallExpression(
86
- call,
87
- visitor.VisitNode(call.Expression),
88
- visitor.VisitNode(call.QuestionDotToken),
89
- nil,
90
- visitor.VisitNodes(call.Arguments),
91
- call.Flags,
92
- )
93
- case shimast.KindNewExpression:
94
- expr := current.AsNewExpression()
95
- return factory.UpdateNewExpression(
96
- expr,
97
- visitor.VisitNode(expr.Expression),
98
- nil,
99
- visitor.VisitNodes(expr.Arguments),
100
- )
101
- default:
102
- return visitor.VisitEachChild(current)
103
- }
104
- }, factory, shimast.NodeVisitorHooks{})
105
- return visitor.VisitNode(node)
106
- }
107
-
108
- func rewriteNestiaIdentifiers(
109
- node *shimast.Node,
110
- substitutions map[string]string,
111
- ) *shimast.Node {
112
- if node == nil || len(substitutions) == 0 {
113
- return node
114
- }
115
- factory := shimast.NewNodeFactory(shimast.NodeFactoryHooks{})
116
- var visitor *shimast.NodeVisitor
117
- visitor = shimast.NewNodeVisitor(func(current *shimast.Node) *shimast.Node {
118
- if current == nil {
119
- return nil
120
- }
121
- switch current.Kind {
122
- case shimast.KindIdentifier:
123
- if replacement, ok := substitutions[current.Text()]; ok {
124
- return rewriteNestiaIdentifierExpression(factory, replacement)
125
- }
126
- return current
127
- case shimast.KindVariableDeclaration:
128
- decl := current.AsVariableDeclaration()
129
- return factory.UpdateVariableDeclaration(
130
- decl,
131
- decl.Name(),
132
- nil,
133
- nil,
134
- visitor.VisitNode(decl.Initializer),
135
- )
136
- case shimast.KindParameter:
137
- parameter := current.AsParameterDeclaration()
138
- return factory.UpdateParameterDeclaration(
139
- parameter,
140
- parameter.Modifiers(),
141
- parameter.DotDotDotToken,
142
- parameter.Name(),
143
- nil,
144
- nil,
145
- visitor.VisitNode(parameter.Initializer),
146
- )
147
- case shimast.KindPropertyAssignment:
148
- assignment := current.AsPropertyAssignment()
149
- return factory.UpdatePropertyAssignment(
150
- assignment,
151
- assignment.Modifiers(),
152
- assignment.Name(),
153
- assignment.PostfixToken,
154
- nil,
155
- visitor.VisitNode(assignment.Initializer),
156
- )
157
- case shimast.KindShorthandPropertyAssignment:
158
- assignment := current.AsShorthandPropertyAssignment()
159
- name := assignment.Name()
160
- if name != nil && name.Kind == shimast.KindIdentifier {
161
- if replacement, ok := substitutions[name.Text()]; ok &&
162
- assignment.ObjectAssignmentInitializer == nil {
163
- return factory.NewPropertyAssignment(
164
- assignment.Modifiers(),
165
- name,
166
- assignment.PostfixToken,
167
- nil,
168
- rewriteNestiaIdentifierExpression(factory, replacement),
169
- )
170
- }
171
- }
172
- return factory.UpdateShorthandPropertyAssignment(
173
- assignment,
174
- assignment.Modifiers(),
175
- name,
176
- assignment.PostfixToken,
177
- nil,
178
- nil,
179
- visitor.VisitNode(assignment.ObjectAssignmentInitializer),
180
- )
181
- case shimast.KindPropertyAccessExpression:
182
- access := current.AsPropertyAccessExpression()
183
- return factory.UpdatePropertyAccessExpression(
184
- access,
185
- visitor.VisitNode(access.Expression),
186
- access.QuestionDotToken,
187
- access.Name(),
188
- access.Flags,
189
- )
190
- default:
191
- return visitor.VisitEachChild(current)
192
- }
193
- }, factory, shimast.NodeVisitorHooks{})
194
- return visitor.VisitNode(node)
195
- }
196
-
197
- func rewriteNestiaIdentifierExpression(
198
- factory *shimast.NodeFactory,
199
- replacement string,
200
- ) *shimast.Node {
201
- parts := []string{}
202
- start := 0
203
- for i := 0; i <= len(replacement); i++ {
204
- if i == len(replacement) || replacement[i] == '.' {
205
- if start < i {
206
- parts = append(parts, replacement[start:i])
207
- }
208
- start = i + 1
209
- }
210
- }
211
- if len(parts) == 0 {
212
- return factory.NewIdentifier(replacement)
213
- }
214
- output := factory.NewIdentifier(parts[0])
215
- for _, part := range parts[1:] {
216
- output = factory.NewPropertyAccessExpression(
217
- output,
218
- nil,
219
- factory.NewIdentifier(part),
220
- shimast.NodeFlagsNone,
221
- )
222
- }
223
- return output
224
- }
225
-
226
9
  func normalizeNestiaSyntheticTokens(node *shimast.Node) {
227
10
  if node == nil {
228
11
  return
@@ -8,7 +8,6 @@ import (
8
8
  "os"
9
9
  "path/filepath"
10
10
  "regexp"
11
- "sort"
12
11
  "strings"
13
12
 
14
13
  shimast "github.com/microsoft/typescript-go/shim/ast"
@@ -74,13 +73,12 @@ func runTransform(args []string) int {
74
73
  // contributor's per-file node transformers run inside one shared EmitContext
75
74
  // and the result SourceFile is printed back as TypeScript (no JS script
76
75
  // transformers), mirroring typia's `transform` subcommand. Injected namespace
77
- // imports stay as ES imports the caller can type-strip per file, so there is
78
- // no text-splice RewriteSet.
76
+ // imports stay as ES imports the caller can type-strip per file.
79
77
  transformDiags := []Diagnostic{}
80
78
  addDiagnostic := func(diag Diagnostic) {
81
79
  transformDiags = append(transformDiags, diag)
82
80
  }
83
- typiaTransform := nestiaTypiaNodeTransform(prog, readTypiaPluginOptions(cwd, *tsconfigPath), addDiagnostic)
81
+ typiaTransform := nestiaTypiaNodeTransform(prog, readTypiaPluginOptions(plan), addDiagnostic)
84
82
  coreTransform := nestiaCoreNodeTransform(prog, plan, addDiagnostic)
85
83
  contributorTransforms, contributorDiags := collectContributorEmitTransforms(prog, plan)
86
84
  if len(contributorDiags) > 0 {
@@ -196,32 +194,6 @@ func writeSingleOutput(text, outPath string) int {
196
194
  return 0
197
195
  }
198
196
 
199
- type SourceRewrite struct {
200
- start int
201
- end int
202
- replacement string
203
- }
204
-
205
- func ApplySourceRewrites(source string, rewrites []SourceRewrite) (string, error) {
206
- sort.SliceStable(rewrites, func(i, j int) bool {
207
- return rewrites[i].start > rewrites[j].start
208
- })
209
- for i := 0; i < len(rewrites)-1; i++ {
210
- if rewrites[i+1].end > rewrites[i].start {
211
- return "", fmt.Errorf("overlapping rewrites: [%d,%d) vs [%d,%d)",
212
- rewrites[i+1].start, rewrites[i+1].end, rewrites[i].start, rewrites[i].end)
213
- }
214
- }
215
- output := source
216
- for _, rewrite := range rewrites {
217
- if rewrite.start < 0 || rewrite.end < rewrite.start || rewrite.end > len(output) {
218
- return "", fmt.Errorf("invalid rewrite range [%d,%d)", rewrite.start, rewrite.end)
219
- }
220
- output = output[:rewrite.start] + rewrite.replacement + output[rewrite.end:]
221
- }
222
- return output, nil
223
- }
224
-
225
197
  func SourceFileText(target any) (string, bool) {
226
198
  type sourceText interface {
227
199
  Text() string
@@ -244,53 +216,11 @@ var (
244
216
  cleanupInputIsParenPattern = regexp.MustCompile(`input is \(([A-Za-z_$][A-Za-z0-9_$.]*)\)`)
245
217
  cleanupCollapseBlankCallPattern = regexp.MustCompile(`\n\n([A-Za-z_$][A-Za-z0-9_$]*\([^;\n]*\);?)`)
246
218
  )
247
-
248
- func cleanupTypeScriptTransformText(text string) string {
249
- text = cleanupTransformedText(text)
250
- text = normalizeParenthesizedTypeAnnotations(text)
251
- text = cleanupImportTypeBlockPattern.ReplaceAllStringFunc(text, func(line string) string {
252
- return cleanupImportTypeLinePattern.ReplaceAllString(line, "import type { $1 } from")
253
- })
254
- text = cleanupImportBlankLinePattern.ReplaceAllString(text, "$1$2")
255
- text = strings.ReplaceAll(text, "=(() =>", "= (() =>")
256
- text = strings.ReplaceAll(text, ": (any) =>", ": any =>")
257
- text = strings.ReplaceAll(text, ": (boolean) =>", ": boolean =>")
258
- text = cleanupInputIsParenPattern.ReplaceAllString(text, "input is $1")
259
- text = strings.ReplaceAll(text, "return (success ? ", "return success ? ")
260
- text = strings.ReplaceAll(text, "}) as any;", "} as any;")
261
- text = strings.ReplaceAll(text, "(() => {\n const ", "(() => { const ")
262
- text = strings.ReplaceAll(text, "(() => {\n let ", "(() => { let ")
263
- text = strings.ReplaceAll(text, "(() => {\n return ", "(() => { return ")
264
- text = strings.ReplaceAll(text, ";\n const ", "; const ")
265
- text = strings.ReplaceAll(text, ";\n let ", "; let ")
266
- text = strings.ReplaceAll(text, ";\n return ", "; return ")
267
- text = strings.ReplaceAll(text, "\n };\n})()", "\n}; })()")
268
- text = strings.ReplaceAll(text, "\n });\n})()", "\n}); })()")
269
- text = strings.ReplaceAll(text, "\n }); let ", "\n}); let ")
270
- text = strings.ReplaceAll(text, ";\n})()", "; })()")
271
- text = strings.ReplaceAll(text, "\n ", "\n ")
272
- text = cleanupCollapseBlankCallPattern.ReplaceAllString(text, "\n$1")
273
- trimmed := strings.TrimRight(text, " \t\r\n")
274
- if strings.HasSuffix(trimmed, ")") && !strings.HasSuffix(trimmed, ";") {
275
- return trimmed + ";\n"
276
- }
277
- if text != "" && !strings.HasSuffix(text, "\n") {
278
- return text + "\n"
279
- }
280
- return text
281
- }
282
-
283
219
  var (
284
220
  normalizeParenArrowTypePattern = regexp.MustCompile(`: \(([A-Za-z_$][A-Za-z0-9_$.]*(<[^()\n;{}]*>)?)\)(\s*=>)`)
285
221
  normalizeParenNullishPattern = regexp.MustCompile(`\| \((null|undefined)\)`)
286
222
  )
287
223
 
288
- func normalizeParenthesizedTypeAnnotations(text string) string {
289
- text = normalizeParenArrowTypePattern.ReplaceAllString(text, ": $1$3")
290
- text = normalizeParenNullishPattern.ReplaceAllString(text, "| $1")
291
- return text
292
- }
293
-
294
224
  func sourceFileKey(cwd string, file string) string {
295
225
  rel, err := filepath.Rel(cwd, filepath.FromSlash(file))
296
226
  if err != nil || rel == ".." || strings.HasPrefix(rel, ".."+string(os.PathSeparator)) {
@@ -298,25 +228,6 @@ func sourceFileKey(cwd string, file string) string {
298
228
  }
299
229
  return filepath.ToSlash(rel)
300
230
  }
301
-
302
- func newTransformCompilerDiagnostic(
303
- file string,
304
- code string,
305
- message string,
306
- ) transformCompilerDiagnostic {
307
- var ptr *string
308
- if file != "" {
309
- normalized := filepath.ToSlash(file)
310
- ptr = &normalized
311
- }
312
- return transformCompilerDiagnostic{
313
- File: ptr,
314
- Category: "error",
315
- Code: code,
316
- MessageText: message,
317
- }
318
- }
319
-
320
231
  func transformDiagnosticToCompilerDiagnostic(
321
232
  diag Diagnostic,
322
233
  ) transformCompilerDiagnostic {