@nestia/core 12.0.0-rc.2 → 12.0.0-rc.4

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 (80) hide show
  1. package/LICENSE +21 -21
  2. package/MIGRATION.md +138 -169
  3. package/lib/decorators/NoTransformConfigurationError.js +5 -5
  4. package/lib/decorators/NoTransformConfigurationError.js.map +1 -1
  5. package/native/cmd/ttsc-nestia/main.go +11 -11
  6. package/native/go.mod +32 -32
  7. package/native/go.sum +54 -54
  8. package/native/plugin/plan.go +102 -102
  9. package/native/transform/ast.go +32 -32
  10. package/native/transform/build.go +388 -380
  11. package/native/transform/cleanup.go +408 -408
  12. package/native/transform/contributor.go +97 -97
  13. package/native/transform/core_querify.go +231 -231
  14. package/native/transform/core_transform.go +1996 -1996
  15. package/native/transform/core_websocket.go +115 -115
  16. package/native/transform/exports.go +13 -13
  17. package/native/transform/mcp_transform.go +414 -414
  18. package/native/transform/node_transform.go +357 -357
  19. package/native/transform/path_rewrite.go +285 -285
  20. package/native/transform/printer.go +244 -244
  21. package/native/transform/rewrite.go +668 -668
  22. package/native/transform/run.go +73 -73
  23. package/native/transform/transform.go +336 -336
  24. package/native/transform/typia_fast.go +375 -352
  25. package/native/transform/typia_replacement.go +24 -24
  26. package/native/transform.cjs +43 -43
  27. package/package.json +9 -9
  28. package/src/adaptors/McpAdaptor.ts +276 -276
  29. package/src/adaptors/WebSocketAdaptor.ts +429 -429
  30. package/src/decorators/DynamicModule.ts +44 -44
  31. package/src/decorators/EncryptedBody.ts +97 -97
  32. package/src/decorators/EncryptedController.ts +40 -40
  33. package/src/decorators/EncryptedModule.ts +98 -98
  34. package/src/decorators/EncryptedRoute.ts +213 -213
  35. package/src/decorators/HumanRoute.ts +21 -21
  36. package/src/decorators/McpRoute.ts +154 -154
  37. package/src/decorators/NoTransformConfigurationError.ts +40 -40
  38. package/src/decorators/PlainBody.ts +76 -76
  39. package/src/decorators/SwaggerCustomizer.ts +97 -97
  40. package/src/decorators/SwaggerExample.ts +180 -180
  41. package/src/decorators/TypedBody.ts +57 -57
  42. package/src/decorators/TypedException.ts +147 -147
  43. package/src/decorators/TypedFormData.ts +187 -187
  44. package/src/decorators/TypedHeaders.ts +66 -66
  45. package/src/decorators/TypedParam.ts +77 -77
  46. package/src/decorators/TypedQuery.ts +234 -234
  47. package/src/decorators/TypedRoute.ts +198 -198
  48. package/src/decorators/WebSocketRoute.ts +242 -242
  49. package/src/decorators/doNotThrowTransformError.ts +5 -5
  50. package/src/decorators/internal/EncryptedConstant.ts +2 -2
  51. package/src/decorators/internal/IMcpRouteReflect.ts +40 -40
  52. package/src/decorators/internal/IWebSocketRouteReflect.ts +23 -23
  53. package/src/decorators/internal/get_path_and_querify.ts +94 -94
  54. package/src/decorators/internal/get_path_and_stringify.ts +110 -110
  55. package/src/decorators/internal/get_text_body.ts +16 -16
  56. package/src/decorators/internal/headers_to_object.ts +11 -11
  57. package/src/decorators/internal/is_request_body_undefined.ts +12 -12
  58. package/src/decorators/internal/load_controller.ts +94 -94
  59. package/src/decorators/internal/route_error.ts +43 -43
  60. package/src/decorators/internal/validate_request_body.ts +64 -64
  61. package/src/decorators/internal/validate_request_form_data.ts +67 -67
  62. package/src/decorators/internal/validate_request_headers.ts +76 -76
  63. package/src/decorators/internal/validate_request_query.ts +83 -83
  64. package/src/index.ts +5 -5
  65. package/src/module.ts +25 -25
  66. package/src/options/IRequestBodyValidator.ts +20 -20
  67. package/src/options/IRequestFormDataProps.ts +27 -27
  68. package/src/options/IRequestHeadersValidator.ts +22 -22
  69. package/src/options/IRequestQueryValidator.ts +20 -20
  70. package/src/options/IResponseBodyQuerifier.ts +25 -25
  71. package/src/options/IResponseBodyStringifier.ts +30 -30
  72. package/src/transform.ts +26 -26
  73. package/src/typings/Creator.ts +3 -3
  74. package/src/typings/get-function-location.d.ts +7 -7
  75. package/src/utils/ArrayUtil.ts +7 -7
  76. package/src/utils/ExceptionManager.ts +115 -115
  77. package/src/utils/Singleton.ts +16 -16
  78. package/src/utils/SourceFinder.ts +54 -54
  79. package/src/utils/VersioningStrategy.ts +27 -27
  80. package/README.md +0 -93
@@ -1,97 +1,97 @@
1
- package transform
2
-
3
- import (
4
- "github.com/samchon/nestia/packages/core/native/plugin"
5
- "github.com/samchon/ttsc/packages/ttsc/driver"
6
- )
7
-
8
- // BuildOutputRewriter patches emitted JavaScript after the core native
9
- // rewrites have been applied. Contributor packages register these from init().
10
- type BuildOutputRewriter struct {
11
- Len func() int
12
- Apply func(outputName string, text string) (string, error)
13
- }
14
-
15
- type buildOutputRewriteCollector func(*driver.Program, plugin.Plan) (*BuildOutputRewriter, []Diagnostic)
16
- type sourceRewriteCollector func(*driver.Program, plugin.Plan, string) (map[string][]SourceRewrite, []Diagnostic)
17
- type emitTransformCollector func(*driver.Program, plugin.Plan) (driver.PluginTransform, []Diagnostic)
18
-
19
- var buildOutputRewriteCollectors []buildOutputRewriteCollector
20
- var sourceRewriteCollectors []sourceRewriteCollector
21
- var emitTransformCollectors []emitTransformCollector
22
-
23
- // RegisterBuildOutputRewriteCollector registers a statically linked
24
- // contributor's emitted-JavaScript rewrite pass.
25
- func RegisterBuildOutputRewriteCollector(collector buildOutputRewriteCollector) {
26
- if collector != nil {
27
- buildOutputRewriteCollectors = append(buildOutputRewriteCollectors, collector)
28
- }
29
- }
30
-
31
- // RegisterSourceRewriteCollector registers a statically linked contributor's
32
- // TypeScript source-to-source rewrite pass.
33
- func RegisterSourceRewriteCollector(collector sourceRewriteCollector) {
34
- if collector != nil {
35
- sourceRewriteCollectors = append(sourceRewriteCollectors, collector)
36
- }
37
- }
38
-
39
- // RegisterEmitTransformCollector registers a statically linked contributor's
40
- // emit-phase AST transformer. The `transform` subcommand runs these inside the
41
- // shared EmitContext alongside the typia and core node transforms, so a linked
42
- // contributor (e.g. @nestia/sdk) participates in the node-path source-to-source
43
- // output the same way its source-rewrite collector did on the legacy text path.
44
- func RegisterEmitTransformCollector(collector emitTransformCollector) {
45
- if collector != nil {
46
- emitTransformCollectors = append(emitTransformCollectors, collector)
47
- }
48
- }
49
-
50
- func collectContributorBuildOutputRewriters(
51
- prog *driver.Program,
52
- plan plugin.Plan,
53
- ) ([]BuildOutputRewriter, []Diagnostic) {
54
- output := []BuildOutputRewriter{}
55
- diagnostics := []Diagnostic{}
56
- for _, collector := range buildOutputRewriteCollectors {
57
- rewriter, diags := collector(prog, plan)
58
- diagnostics = append(diagnostics, diags...)
59
- if rewriter != nil && rewriter.Apply != nil {
60
- output = append(output, *rewriter)
61
- }
62
- }
63
- return output, diagnostics
64
- }
65
-
66
- func collectContributorSourceRewriteMap(
67
- prog *driver.Program,
68
- plan plugin.Plan,
69
- onlyFile string,
70
- ) (map[string][]SourceRewrite, []Diagnostic) {
71
- output := map[string][]SourceRewrite{}
72
- diagnostics := []Diagnostic{}
73
- for _, collector := range sourceRewriteCollectors {
74
- rewrites, diags := collector(prog, plan, onlyFile)
75
- diagnostics = append(diagnostics, diags...)
76
- for file, entries := range rewrites {
77
- output[file] = append(output[file], entries...)
78
- }
79
- }
80
- return output, diagnostics
81
- }
82
-
83
- func collectContributorEmitTransforms(
84
- prog *driver.Program,
85
- plan plugin.Plan,
86
- ) ([]driver.PluginTransform, []Diagnostic) {
87
- transforms := []driver.PluginTransform{}
88
- diagnostics := []Diagnostic{}
89
- for _, collector := range emitTransformCollectors {
90
- t, diags := collector(prog, plan)
91
- diagnostics = append(diagnostics, diags...)
92
- if t != nil {
93
- transforms = append(transforms, t)
94
- }
95
- }
96
- return transforms, diagnostics
97
- }
1
+ package transform
2
+
3
+ import (
4
+ "github.com/samchon/nestia/packages/core/native/plugin"
5
+ "github.com/samchon/ttsc/packages/ttsc/driver"
6
+ )
7
+
8
+ // BuildOutputRewriter patches emitted JavaScript after the core native
9
+ // rewrites have been applied. Contributor packages register these from init().
10
+ type BuildOutputRewriter struct {
11
+ Len func() int
12
+ Apply func(outputName string, text string) (string, error)
13
+ }
14
+
15
+ type buildOutputRewriteCollector func(*driver.Program, plugin.Plan) (*BuildOutputRewriter, []Diagnostic)
16
+ type sourceRewriteCollector func(*driver.Program, plugin.Plan, string) (map[string][]SourceRewrite, []Diagnostic)
17
+ type emitTransformCollector func(*driver.Program, plugin.Plan) (driver.PluginTransform, []Diagnostic)
18
+
19
+ var buildOutputRewriteCollectors []buildOutputRewriteCollector
20
+ var sourceRewriteCollectors []sourceRewriteCollector
21
+ var emitTransformCollectors []emitTransformCollector
22
+
23
+ // RegisterBuildOutputRewriteCollector registers a statically linked
24
+ // contributor's emitted-JavaScript rewrite pass.
25
+ func RegisterBuildOutputRewriteCollector(collector buildOutputRewriteCollector) {
26
+ if collector != nil {
27
+ buildOutputRewriteCollectors = append(buildOutputRewriteCollectors, collector)
28
+ }
29
+ }
30
+
31
+ // RegisterSourceRewriteCollector registers a statically linked contributor's
32
+ // TypeScript source-to-source rewrite pass.
33
+ func RegisterSourceRewriteCollector(collector sourceRewriteCollector) {
34
+ if collector != nil {
35
+ sourceRewriteCollectors = append(sourceRewriteCollectors, collector)
36
+ }
37
+ }
38
+
39
+ // RegisterEmitTransformCollector registers a statically linked contributor's
40
+ // emit-phase AST transformer. The `transform` subcommand runs these inside the
41
+ // shared EmitContext alongside the typia and core node transforms, so a linked
42
+ // contributor (e.g. @nestia/sdk) participates in the node-path source-to-source
43
+ // output the same way its source-rewrite collector did on the legacy text path.
44
+ func RegisterEmitTransformCollector(collector emitTransformCollector) {
45
+ if collector != nil {
46
+ emitTransformCollectors = append(emitTransformCollectors, collector)
47
+ }
48
+ }
49
+
50
+ func collectContributorBuildOutputRewriters(
51
+ prog *driver.Program,
52
+ plan plugin.Plan,
53
+ ) ([]BuildOutputRewriter, []Diagnostic) {
54
+ output := []BuildOutputRewriter{}
55
+ diagnostics := []Diagnostic{}
56
+ for _, collector := range buildOutputRewriteCollectors {
57
+ rewriter, diags := collector(prog, plan)
58
+ diagnostics = append(diagnostics, diags...)
59
+ if rewriter != nil && rewriter.Apply != nil {
60
+ output = append(output, *rewriter)
61
+ }
62
+ }
63
+ return output, diagnostics
64
+ }
65
+
66
+ func collectContributorSourceRewriteMap(
67
+ prog *driver.Program,
68
+ plan plugin.Plan,
69
+ onlyFile string,
70
+ ) (map[string][]SourceRewrite, []Diagnostic) {
71
+ output := map[string][]SourceRewrite{}
72
+ diagnostics := []Diagnostic{}
73
+ for _, collector := range sourceRewriteCollectors {
74
+ rewrites, diags := collector(prog, plan, onlyFile)
75
+ diagnostics = append(diagnostics, diags...)
76
+ for file, entries := range rewrites {
77
+ output[file] = append(output[file], entries...)
78
+ }
79
+ }
80
+ return output, diagnostics
81
+ }
82
+
83
+ func collectContributorEmitTransforms(
84
+ prog *driver.Program,
85
+ plan plugin.Plan,
86
+ ) ([]driver.PluginTransform, []Diagnostic) {
87
+ transforms := []driver.PluginTransform{}
88
+ diagnostics := []Diagnostic{}
89
+ for _, collector := range emitTransformCollectors {
90
+ t, diags := collector(prog, plan)
91
+ diagnostics = append(diagnostics, diags...)
92
+ if t != nil {
93
+ transforms = append(transforms, t)
94
+ }
95
+ }
96
+ return transforms, diagnostics
97
+ }
@@ -1,231 +1,231 @@
1
- package transform
2
-
3
- import (
4
- "fmt"
5
-
6
- shimast "github.com/microsoft/typescript-go/shim/ast"
7
- shimchecker "github.com/microsoft/typescript-go/shim/checker"
8
- shimprinter "github.com/microsoft/typescript-go/shim/printer"
9
- "github.com/samchon/ttsc/packages/ttsc/driver"
10
- nativecontext "github.com/samchon/typia/packages/typia/native/core/context"
11
- nativefactories "github.com/samchon/typia/packages/typia/native/core/factories"
12
- nativeprogrammers "github.com/samchon/typia/packages/typia/native/core/programmers"
13
- nativehttp "github.com/samchon/typia/packages/typia/native/core/programmers/http"
14
- schemametadata "github.com/samchon/typia/packages/typia/native/core/schemas/metadata"
15
- )
16
-
17
- func nestiaCoreHttpQuerifyProgrammer(prog *driver.Program, ec *shimprinter.EmitContext, typ *shimchecker.Type) *shimast.Node {
18
- collection := schemametadata.NewMetadataCollection()
19
- result := nativefactories.MetadataFactory.Analyze(nativefactories.MetadataFactory_IProps{
20
- Checker: prog.Checker,
21
- Options: nativefactories.MetadataFactory_IOptions{
22
- Escape: false,
23
- Constant: true,
24
- Absorb: true,
25
- Validate: func(next struct {
26
- Metadata *schemametadata.MetadataSchema
27
- Explore nativefactories.MetadataFactory_IExplore
28
- Top *schemametadata.MetadataSchema
29
- }) []string {
30
- return nativehttp.HttpQueryProgrammer.Validate(struct {
31
- Metadata *schemametadata.MetadataSchema
32
- Explore nativefactories.MetadataFactory_IExplore
33
- Top *schemametadata.MetadataSchema
34
- AllowOptional bool
35
- }{
36
- Metadata: next.Metadata,
37
- Explore: next.Explore,
38
- Top: next.Top,
39
- AllowOptional: false,
40
- })
41
- },
42
- },
43
- Components: collection,
44
- Type: typ,
45
- })
46
- if result.Success == false {
47
- panic(fmt.Errorf("failed to analyze query-string metadata: %d error(s)", len(result.Errors)))
48
- }
49
- statements := []*shimast.Node{
50
- nativefactories.StatementFactory.Constant(nativefactories.StatementFactory_ConstantProps{
51
- Name: "output",
52
- Value: nestiaCoreFactory.NewNewExpression(
53
- nestiaCoreFactory.NewIdentifier("URLSearchParams"),
54
- nil,
55
- nestiaCoreFactory.NewNodeList([]*shimast.Node{}),
56
- ),
57
- }),
58
- }
59
- if result.Data != nil && len(result.Data.Objects) != 0 && result.Data.Objects[0] != nil && result.Data.Objects[0].Type != nil {
60
- for _, property := range result.Data.Objects[0].Type.Properties {
61
- key, ok := nestiaCorePropertyStringKey(property)
62
- if ok == false || property == nil || property.Value == nil {
63
- continue
64
- }
65
- statements = append(statements, nestiaCoreFactory.NewExpressionStatement(
66
- nestiaCoreHttpQuerifyDecode(key, property.Value, ec),
67
- ))
68
- }
69
- }
70
- statements = append(statements, nestiaCoreFactory.NewReturnStatement(nestiaCoreFactory.NewIdentifier("output")))
71
- return nestiaCoreFactory.NewArrowFunction(
72
- nil,
73
- nil,
74
- nestiaCoreFactory.NewNodeList([]*shimast.Node{
75
- nativefactories.IdentifierFactory.Parameter("input", nil, nil),
76
- }),
77
- nil,
78
- nil,
79
- nestiaCoreFactory.NewToken(shimast.KindEqualsGreaterThanToken),
80
- nestiaCoreFactory.NewBlock(nestiaCoreFactory.NewNodeList(statements), true),
81
- )
82
- }
83
-
84
- func nestiaCoreHttpAssertQuerifyProgrammer(prog *driver.Program, importer *nativecontext.ImportProgrammer, ec *shimprinter.EmitContext, modulo *shimast.Node, typ *shimchecker.Type) *shimast.Node {
85
- context := nestiaCoreTypiaContext(prog, importer, ec, false, false, false)
86
- name := nestiaCoreTypeName(prog, typ)
87
- return nestiaCoreQueryWrapperArrow([]*shimast.Node{
88
- nativefactories.StatementFactory.Constant(nativefactories.StatementFactory_ConstantProps{
89
- Name: "assert",
90
- Value: nativeprogrammers.AssertProgrammer.Write(nativeprogrammers.AssertProgrammer_IProps{
91
- Context: context,
92
- Modulo: modulo,
93
- Type: typ,
94
- Name: name,
95
- Config: nativeprogrammers.AssertProgrammer_IConfig{Equals: false, Guard: false},
96
- }),
97
- }),
98
- nativefactories.StatementFactory.Constant(nativefactories.StatementFactory_ConstantProps{
99
- Name: "stringify",
100
- Value: nestiaCoreHttpQuerifyProgrammer(prog, ec, typ),
101
- }),
102
- nestiaCoreFactory.NewReturnStatement(nestiaCoreCall("stringify", nestiaCoreCall("assert", nestiaCoreFactory.NewIdentifier("input")))),
103
- })
104
- }
105
-
106
- func nestiaCoreHttpIsQuerifyProgrammer(prog *driver.Program, importer *nativecontext.ImportProgrammer, ec *shimprinter.EmitContext, modulo *shimast.Node, typ *shimchecker.Type) *shimast.Node {
107
- context := nestiaCoreTypiaContext(prog, importer, ec, false, false, false)
108
- name := nestiaCoreTypeName(prog, typ)
109
- return nestiaCoreQueryWrapperArrow([]*shimast.Node{
110
- nativefactories.StatementFactory.Constant(nativefactories.StatementFactory_ConstantProps{
111
- Name: "is",
112
- Value: nativeprogrammers.IsProgrammer.Write(nativeprogrammers.IsProgrammer_IProps{
113
- Context: context,
114
- Modulo: modulo,
115
- Type: typ,
116
- Name: name,
117
- Config: nativeprogrammers.IsProgrammer_IConfig{Equals: false},
118
- }),
119
- }),
120
- nativefactories.StatementFactory.Constant(nativefactories.StatementFactory_ConstantProps{
121
- Name: "stringify",
122
- Value: nestiaCoreHttpQuerifyProgrammer(prog, ec, typ),
123
- }),
124
- nestiaCoreFactory.NewReturnStatement(nestiaCoreFactory.NewConditionalExpression(
125
- nestiaCoreCall("is", nestiaCoreFactory.NewIdentifier("input")),
126
- nil,
127
- nestiaCoreCall("stringify", nestiaCoreFactory.NewIdentifier("input")),
128
- nil,
129
- nestiaCoreFactory.NewKeywordExpression(shimast.KindNullKeyword),
130
- )),
131
- })
132
- }
133
-
134
- func nestiaCoreHttpValidateQuerifyProgrammer(prog *driver.Program, importer *nativecontext.ImportProgrammer, ec *shimprinter.EmitContext, modulo *shimast.Node, typ *shimchecker.Type) *shimast.Node {
135
- context := nestiaCoreTypiaContext(prog, importer, ec, true, false, false)
136
- name := nestiaCoreTypeName(prog, typ)
137
- return nestiaCoreQueryWrapperArrow([]*shimast.Node{
138
- nativefactories.StatementFactory.Constant(nativefactories.StatementFactory_ConstantProps{
139
- Name: "validate",
140
- Value: nativeprogrammers.ValidateProgrammer.Write(nativeprogrammers.ValidateProgrammer_IProps{
141
- Context: context,
142
- Modulo: modulo,
143
- Type: typ,
144
- Name: name,
145
- Config: nativeprogrammers.ValidateProgrammer_IConfig{Equals: false},
146
- }),
147
- }),
148
- nativefactories.StatementFactory.Constant(nativefactories.StatementFactory_ConstantProps{
149
- Name: "query",
150
- Value: nestiaCoreHttpQuerifyProgrammer(prog, ec, typ),
151
- }),
152
- nativefactories.StatementFactory.Constant(nativefactories.StatementFactory_ConstantProps{
153
- Name: "output",
154
- Value: nestiaCoreCall("query", nestiaCoreFactory.NewIdentifier("input")),
155
- }),
156
- nestiaCoreFactory.NewReturnStatement(nestiaCoreFactory.NewAsExpression(
157
- nestiaCoreCall("validate", nestiaCoreFactory.NewIdentifier("output")),
158
- nativefactories.TypeFactory.Keyword("any"),
159
- )),
160
- })
161
- }
162
-
163
- func nestiaCoreQueryWrapperArrow(statements []*shimast.Node) *shimast.Node {
164
- return nestiaCoreFactory.NewArrowFunction(
165
- nil,
166
- nil,
167
- nestiaCoreFactory.NewNodeList([]*shimast.Node{
168
- nativefactories.IdentifierFactory.Parameter("input", nil, nil),
169
- }),
170
- nil,
171
- nil,
172
- nestiaCoreFactory.NewToken(shimast.KindEqualsGreaterThanToken),
173
- nestiaCoreFactory.NewBlock(nestiaCoreFactory.NewNodeList(statements), true),
174
- )
175
- }
176
-
177
- func nestiaCoreHttpQuerifyDecode(key string, value *schemametadata.MetadataSchema, ec *shimprinter.EmitContext) *shimast.Node {
178
- if len(value.Arrays) != 0 {
179
- return nestiaCoreFactory.NewCallExpression(
180
- nativefactories.IdentifierFactory.Access(
181
- ec,
182
- nativefactories.IdentifierFactory.Access(ec, nestiaCoreFactory.NewIdentifier("input"), key),
183
- "forEach",
184
- ),
185
- nil,
186
- nil,
187
- nestiaCoreFactory.NewNodeList([]*shimast.Node{
188
- nestiaCoreFactory.NewArrowFunction(
189
- nil,
190
- nil,
191
- nestiaCoreFactory.NewNodeList([]*shimast.Node{
192
- nativefactories.IdentifierFactory.Parameter("elem", nil, nil),
193
- }),
194
- nil,
195
- nil,
196
- nestiaCoreFactory.NewToken(shimast.KindEqualsGreaterThanToken),
197
- nestiaCoreHttpQuerifyAppend(key, nestiaCoreFactory.NewIdentifier("elem"), ec),
198
- ),
199
- }),
200
- shimast.NodeFlagsNone,
201
- )
202
- }
203
- return nestiaCoreHttpQuerifyAppend(
204
- key,
205
- nativefactories.IdentifierFactory.Access(ec, nestiaCoreFactory.NewIdentifier("input"), key),
206
- ec,
207
- )
208
- }
209
-
210
- func nestiaCoreHttpQuerifyAppend(key string, elem *shimast.Node, ec *shimprinter.EmitContext) *shimast.Node {
211
- return nestiaCoreFactory.NewCallExpression(
212
- nativefactories.IdentifierFactory.Access(ec, nestiaCoreFactory.NewIdentifier("output"), "append"),
213
- nil,
214
- nil,
215
- nestiaCoreFactory.NewNodeList([]*shimast.Node{
216
- nestiaCoreFactory.NewStringLiteral(key, shimast.TokenFlagsNone),
217
- elem,
218
- }),
219
- shimast.NodeFlagsNone,
220
- )
221
- }
222
-
223
- func nestiaCoreCall(name string, args ...*shimast.Node) *shimast.Node {
224
- return nestiaCoreFactory.NewCallExpression(
225
- nestiaCoreFactory.NewIdentifier(name),
226
- nil,
227
- nil,
228
- nestiaCoreFactory.NewNodeList(args),
229
- shimast.NodeFlagsNone,
230
- )
231
- }
1
+ package transform
2
+
3
+ import (
4
+ "fmt"
5
+
6
+ shimast "github.com/microsoft/typescript-go/shim/ast"
7
+ shimchecker "github.com/microsoft/typescript-go/shim/checker"
8
+ shimprinter "github.com/microsoft/typescript-go/shim/printer"
9
+ "github.com/samchon/ttsc/packages/ttsc/driver"
10
+ nativecontext "github.com/samchon/typia/packages/typia/native/core/context"
11
+ nativefactories "github.com/samchon/typia/packages/typia/native/core/factories"
12
+ nativeprogrammers "github.com/samchon/typia/packages/typia/native/core/programmers"
13
+ nativehttp "github.com/samchon/typia/packages/typia/native/core/programmers/http"
14
+ schemametadata "github.com/samchon/typia/packages/typia/native/core/schemas/metadata"
15
+ )
16
+
17
+ func nestiaCoreHttpQuerifyProgrammer(prog *driver.Program, ec *shimprinter.EmitContext, typ *shimchecker.Type) *shimast.Node {
18
+ collection := schemametadata.NewMetadataCollection()
19
+ result := nativefactories.MetadataFactory.Analyze(nativefactories.MetadataFactory_IProps{
20
+ Checker: prog.Checker,
21
+ Options: nativefactories.MetadataFactory_IOptions{
22
+ Escape: false,
23
+ Constant: true,
24
+ Absorb: true,
25
+ Validate: func(next struct {
26
+ Metadata *schemametadata.MetadataSchema
27
+ Explore nativefactories.MetadataFactory_IExplore
28
+ Top *schemametadata.MetadataSchema
29
+ }) []string {
30
+ return nativehttp.HttpQueryProgrammer.Validate(struct {
31
+ Metadata *schemametadata.MetadataSchema
32
+ Explore nativefactories.MetadataFactory_IExplore
33
+ Top *schemametadata.MetadataSchema
34
+ AllowOptional bool
35
+ }{
36
+ Metadata: next.Metadata,
37
+ Explore: next.Explore,
38
+ Top: next.Top,
39
+ AllowOptional: false,
40
+ })
41
+ },
42
+ },
43
+ Components: collection,
44
+ Type: typ,
45
+ })
46
+ if result.Success == false {
47
+ panic(fmt.Errorf("failed to analyze query-string metadata: %d error(s)", len(result.Errors)))
48
+ }
49
+ statements := []*shimast.Node{
50
+ nativefactories.StatementFactory.Constant(nativefactories.StatementFactory_ConstantProps{
51
+ Name: "output",
52
+ Value: nestiaCoreFactory.NewNewExpression(
53
+ nestiaCoreFactory.NewIdentifier("URLSearchParams"),
54
+ nil,
55
+ nestiaCoreFactory.NewNodeList([]*shimast.Node{}),
56
+ ),
57
+ }),
58
+ }
59
+ if result.Data != nil && len(result.Data.Objects) != 0 && result.Data.Objects[0] != nil && result.Data.Objects[0].Type != nil {
60
+ for _, property := range result.Data.Objects[0].Type.Properties {
61
+ key, ok := nestiaCorePropertyStringKey(property)
62
+ if ok == false || property == nil || property.Value == nil {
63
+ continue
64
+ }
65
+ statements = append(statements, nestiaCoreFactory.NewExpressionStatement(
66
+ nestiaCoreHttpQuerifyDecode(key, property.Value, ec),
67
+ ))
68
+ }
69
+ }
70
+ statements = append(statements, nestiaCoreFactory.NewReturnStatement(nestiaCoreFactory.NewIdentifier("output")))
71
+ return nestiaCoreFactory.NewArrowFunction(
72
+ nil,
73
+ nil,
74
+ nestiaCoreFactory.NewNodeList([]*shimast.Node{
75
+ nativefactories.IdentifierFactory.Parameter("input", nil, nil),
76
+ }),
77
+ nil,
78
+ nil,
79
+ nestiaCoreFactory.NewToken(shimast.KindEqualsGreaterThanToken),
80
+ nestiaCoreFactory.NewBlock(nestiaCoreFactory.NewNodeList(statements), true),
81
+ )
82
+ }
83
+
84
+ func nestiaCoreHttpAssertQuerifyProgrammer(prog *driver.Program, importer *nativecontext.ImportProgrammer, ec *shimprinter.EmitContext, modulo *shimast.Node, typ *shimchecker.Type) *shimast.Node {
85
+ context := nestiaCoreTypiaContext(prog, importer, ec, false, false, false)
86
+ name := nestiaCoreTypeName(prog, typ)
87
+ return nestiaCoreQueryWrapperArrow([]*shimast.Node{
88
+ nativefactories.StatementFactory.Constant(nativefactories.StatementFactory_ConstantProps{
89
+ Name: "assert",
90
+ Value: nativeprogrammers.AssertProgrammer.Write(nativeprogrammers.AssertProgrammer_IProps{
91
+ Context: context,
92
+ Modulo: modulo,
93
+ Type: typ,
94
+ Name: name,
95
+ Config: nativeprogrammers.AssertProgrammer_IConfig{Equals: false, Guard: false},
96
+ }),
97
+ }),
98
+ nativefactories.StatementFactory.Constant(nativefactories.StatementFactory_ConstantProps{
99
+ Name: "stringify",
100
+ Value: nestiaCoreHttpQuerifyProgrammer(prog, ec, typ),
101
+ }),
102
+ nestiaCoreFactory.NewReturnStatement(nestiaCoreCall("stringify", nestiaCoreCall("assert", nestiaCoreFactory.NewIdentifier("input")))),
103
+ })
104
+ }
105
+
106
+ func nestiaCoreHttpIsQuerifyProgrammer(prog *driver.Program, importer *nativecontext.ImportProgrammer, ec *shimprinter.EmitContext, modulo *shimast.Node, typ *shimchecker.Type) *shimast.Node {
107
+ context := nestiaCoreTypiaContext(prog, importer, ec, false, false, false)
108
+ name := nestiaCoreTypeName(prog, typ)
109
+ return nestiaCoreQueryWrapperArrow([]*shimast.Node{
110
+ nativefactories.StatementFactory.Constant(nativefactories.StatementFactory_ConstantProps{
111
+ Name: "is",
112
+ Value: nativeprogrammers.IsProgrammer.Write(nativeprogrammers.IsProgrammer_IProps{
113
+ Context: context,
114
+ Modulo: modulo,
115
+ Type: typ,
116
+ Name: name,
117
+ Config: nativeprogrammers.IsProgrammer_IConfig{Equals: false},
118
+ }),
119
+ }),
120
+ nativefactories.StatementFactory.Constant(nativefactories.StatementFactory_ConstantProps{
121
+ Name: "stringify",
122
+ Value: nestiaCoreHttpQuerifyProgrammer(prog, ec, typ),
123
+ }),
124
+ nestiaCoreFactory.NewReturnStatement(nestiaCoreFactory.NewConditionalExpression(
125
+ nestiaCoreCall("is", nestiaCoreFactory.NewIdentifier("input")),
126
+ nil,
127
+ nestiaCoreCall("stringify", nestiaCoreFactory.NewIdentifier("input")),
128
+ nil,
129
+ nestiaCoreFactory.NewKeywordExpression(shimast.KindNullKeyword),
130
+ )),
131
+ })
132
+ }
133
+
134
+ func nestiaCoreHttpValidateQuerifyProgrammer(prog *driver.Program, importer *nativecontext.ImportProgrammer, ec *shimprinter.EmitContext, modulo *shimast.Node, typ *shimchecker.Type) *shimast.Node {
135
+ context := nestiaCoreTypiaContext(prog, importer, ec, true, false, false)
136
+ name := nestiaCoreTypeName(prog, typ)
137
+ return nestiaCoreQueryWrapperArrow([]*shimast.Node{
138
+ nativefactories.StatementFactory.Constant(nativefactories.StatementFactory_ConstantProps{
139
+ Name: "validate",
140
+ Value: nativeprogrammers.ValidateProgrammer.Write(nativeprogrammers.ValidateProgrammer_IProps{
141
+ Context: context,
142
+ Modulo: modulo,
143
+ Type: typ,
144
+ Name: name,
145
+ Config: nativeprogrammers.ValidateProgrammer_IConfig{Equals: false},
146
+ }),
147
+ }),
148
+ nativefactories.StatementFactory.Constant(nativefactories.StatementFactory_ConstantProps{
149
+ Name: "query",
150
+ Value: nestiaCoreHttpQuerifyProgrammer(prog, ec, typ),
151
+ }),
152
+ nativefactories.StatementFactory.Constant(nativefactories.StatementFactory_ConstantProps{
153
+ Name: "output",
154
+ Value: nestiaCoreCall("query", nestiaCoreFactory.NewIdentifier("input")),
155
+ }),
156
+ nestiaCoreFactory.NewReturnStatement(nestiaCoreFactory.NewAsExpression(
157
+ nestiaCoreCall("validate", nestiaCoreFactory.NewIdentifier("output")),
158
+ nativefactories.TypeFactory.Keyword("any"),
159
+ )),
160
+ })
161
+ }
162
+
163
+ func nestiaCoreQueryWrapperArrow(statements []*shimast.Node) *shimast.Node {
164
+ return nestiaCoreFactory.NewArrowFunction(
165
+ nil,
166
+ nil,
167
+ nestiaCoreFactory.NewNodeList([]*shimast.Node{
168
+ nativefactories.IdentifierFactory.Parameter("input", nil, nil),
169
+ }),
170
+ nil,
171
+ nil,
172
+ nestiaCoreFactory.NewToken(shimast.KindEqualsGreaterThanToken),
173
+ nestiaCoreFactory.NewBlock(nestiaCoreFactory.NewNodeList(statements), true),
174
+ )
175
+ }
176
+
177
+ func nestiaCoreHttpQuerifyDecode(key string, value *schemametadata.MetadataSchema, ec *shimprinter.EmitContext) *shimast.Node {
178
+ if len(value.Arrays) != 0 {
179
+ return nestiaCoreFactory.NewCallExpression(
180
+ nativefactories.IdentifierFactory.Access(
181
+ ec,
182
+ nativefactories.IdentifierFactory.Access(ec, nestiaCoreFactory.NewIdentifier("input"), key),
183
+ "forEach",
184
+ ),
185
+ nil,
186
+ nil,
187
+ nestiaCoreFactory.NewNodeList([]*shimast.Node{
188
+ nestiaCoreFactory.NewArrowFunction(
189
+ nil,
190
+ nil,
191
+ nestiaCoreFactory.NewNodeList([]*shimast.Node{
192
+ nativefactories.IdentifierFactory.Parameter("elem", nil, nil),
193
+ }),
194
+ nil,
195
+ nil,
196
+ nestiaCoreFactory.NewToken(shimast.KindEqualsGreaterThanToken),
197
+ nestiaCoreHttpQuerifyAppend(key, nestiaCoreFactory.NewIdentifier("elem"), ec),
198
+ ),
199
+ }),
200
+ shimast.NodeFlagsNone,
201
+ )
202
+ }
203
+ return nestiaCoreHttpQuerifyAppend(
204
+ key,
205
+ nativefactories.IdentifierFactory.Access(ec, nestiaCoreFactory.NewIdentifier("input"), key),
206
+ ec,
207
+ )
208
+ }
209
+
210
+ func nestiaCoreHttpQuerifyAppend(key string, elem *shimast.Node, ec *shimprinter.EmitContext) *shimast.Node {
211
+ return nestiaCoreFactory.NewCallExpression(
212
+ nativefactories.IdentifierFactory.Access(ec, nestiaCoreFactory.NewIdentifier("output"), "append"),
213
+ nil,
214
+ nil,
215
+ nestiaCoreFactory.NewNodeList([]*shimast.Node{
216
+ nestiaCoreFactory.NewStringLiteral(key, shimast.TokenFlagsNone),
217
+ elem,
218
+ }),
219
+ shimast.NodeFlagsNone,
220
+ )
221
+ }
222
+
223
+ func nestiaCoreCall(name string, args ...*shimast.Node) *shimast.Node {
224
+ return nestiaCoreFactory.NewCallExpression(
225
+ nestiaCoreFactory.NewIdentifier(name),
226
+ nil,
227
+ nil,
228
+ nestiaCoreFactory.NewNodeList(args),
229
+ shimast.NodeFlagsNone,
230
+ )
231
+ }