@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.
Files changed (61) hide show
  1. package/README.md +13 -0
  2. package/dist/index.cjs +1 -0
  3. package/dist/index.d.ts +3 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +966 -0
  6. package/dist/reflection/annotations.d.ts +15 -0
  7. package/dist/reflection/annotations.d.ts.map +1 -0
  8. package/dist/reflection/compact-metadata.d.ts +18 -0
  9. package/dist/reflection/compact-metadata.d.ts.map +1 -0
  10. package/dist/reflection/conversion.d.ts +15 -0
  11. package/dist/reflection/conversion.d.ts.map +1 -0
  12. package/dist/reflection/deserializer.d.ts +15 -0
  13. package/dist/reflection/deserializer.d.ts.map +1 -0
  14. package/dist/reflection/errors.d.ts +8 -0
  15. package/dist/reflection/errors.d.ts.map +1 -0
  16. package/dist/reflection/index.d.ts +10 -0
  17. package/dist/reflection/index.d.ts.map +1 -0
  18. package/dist/reflection/metadata-store.d.ts +20 -0
  19. package/dist/reflection/metadata-store.d.ts.map +1 -0
  20. package/dist/reflection/model.d.ts +273 -0
  21. package/dist/reflection/model.d.ts.map +1 -0
  22. package/dist/reflection/primitive-conversion.d.ts +2 -0
  23. package/dist/reflection/primitive-conversion.d.ts.map +1 -0
  24. package/dist/reflection/reflection-class.d.ts +60 -0
  25. package/dist/reflection/reflection-class.d.ts.map +1 -0
  26. package/dist/reflection/type-utils.d.ts +34 -0
  27. package/dist/reflection/type-utils.d.ts.map +1 -0
  28. package/dist/type-compiler/download-prebuilt.cjs +114 -0
  29. package/dist/type-compiler/go/ast_expression.go +187 -0
  30. package/dist/type-compiler/go/ast_metadata.go +388 -0
  31. package/dist/type-compiler/go/collect.go +963 -0
  32. package/dist/type-compiler/go/compact_metadata.go +553 -0
  33. package/dist/type-compiler/go/emission_plan.go +340 -0
  34. package/dist/type-compiler/go/emit_ast.go +557 -0
  35. package/dist/type-compiler/go/emit_ast_test.go +558 -0
  36. package/dist/type-compiler/go/go.mod +10 -0
  37. package/dist/type-compiler/go/plugin.go +359 -0
  38. package/dist/type-compiler/go/plugin_test.go +1206 -0
  39. package/dist/type-compiler/go/precompute.go +86 -0
  40. package/dist/type-compiler/go/receive_type.go +912 -0
  41. package/dist/type-compiler/go/resolve.go +265 -0
  42. package/dist/type-compiler/go/source_scan.go +51 -0
  43. package/dist/type-compiler/go/text_parse.go +734 -0
  44. package/dist/type-compiler/go/type_expr.go +1291 -0
  45. package/dist/type-compiler/go/typia_expr.go +2316 -0
  46. package/dist/type-compiler/index.cjs +43 -0
  47. package/dist/type-compiler/pnp.cjs +474 -0
  48. package/dist/type-compiler/prebuilt.cjs +324 -0
  49. package/dist/type-metadata-runtime.cjs +1 -0
  50. package/dist/type-metadata-runtime.d.ts +2 -0
  51. package/dist/type-metadata-runtime.d.ts.map +1 -0
  52. package/dist/type-metadata-runtime.js +107 -0
  53. package/dist/types/index.d.ts +4 -0
  54. package/dist/types/index.d.ts.map +1 -0
  55. package/dist/types/primitives.d.ts +33 -0
  56. package/dist/types/primitives.d.ts.map +1 -0
  57. package/dist/types/runtime.d.ts +2 -0
  58. package/dist/types/runtime.d.ts.map +1 -0
  59. package/dist/types/type-annotations.d.ts +28 -0
  60. package/dist/types/type-annotations.d.ts.map +1 -0
  61. package/package.json +47 -0
@@ -0,0 +1,359 @@
1
+ package main
2
+
3
+ import (
4
+ "encoding/json"
5
+ "flag"
6
+ "fmt"
7
+ "os"
8
+ "path/filepath"
9
+ "strings"
10
+
11
+ shimast "github.com/microsoft/typescript-go/shim/ast"
12
+ shimchecker "github.com/microsoft/typescript-go/shim/checker"
13
+
14
+ "github.com/samchon/ttsc/packages/ttsc/driver"
15
+ )
16
+
17
+ const foundationPackageSpec = "@zyno-io/ts-server-foundation"
18
+ const reflectionPackageSpec = "@zyno-io/ts-reflection"
19
+
20
+ type registry struct {
21
+ files map[string]*fileInfo
22
+ byPath map[string]*fileInfo
23
+ checker *shimchecker.Checker
24
+ typiaCache map[typiaCacheKey]string
25
+ typiaFailures map[*shimchecker.Type]bool
26
+ classes map[string]*classInfo
27
+ external map[string]map[string][]functionInfo
28
+ externalPackageRoots map[string]string
29
+ }
30
+
31
+ type typiaCacheKey struct {
32
+ typ *shimchecker.Type
33
+ moduleKey string
34
+ raw string
35
+ pos int
36
+ }
37
+
38
+ type fileInfo struct {
39
+ file *shimast.SourceFile
40
+ moduleKey string
41
+ precompute bool
42
+ decoratedMethodsOnly bool
43
+ aliases map[string]aliasInfo
44
+ interfaces map[string][]interfaceInfo
45
+ enums map[string]enumInfo
46
+ classes []*classInfo
47
+ functions map[string][]functionInfo
48
+ imports map[string]importRef
49
+ reexports map[string]importRef
50
+ exportStar []importRef
51
+ calls []callInfo
52
+ }
53
+
54
+ type aliasInfo struct {
55
+ body string
56
+ params []string
57
+ defaults []string
58
+ typeNode *shimast.Node
59
+ metadataText string
60
+ metadataTooLarge bool
61
+ exported bool
62
+ pos int
63
+ }
64
+
65
+ type interfaceInfo struct {
66
+ body string
67
+ params []string
68
+ defaults []string
69
+ extends []string
70
+ properties []utilityProperty
71
+ exported bool
72
+ pos int
73
+ source string
74
+ }
75
+
76
+ type enumInfo struct {
77
+ name string
78
+ values []string
79
+ pos int
80
+ }
81
+
82
+ type importRef struct {
83
+ source string
84
+ exportName string
85
+ spec string
86
+ }
87
+
88
+ type classInfo struct {
89
+ name string
90
+ pos int
91
+ end int
92
+ ambient bool
93
+ properties []propertyInfo
94
+ methods []methodInfo
95
+ staticMethods []methodInfo
96
+ ctor []paramInfo
97
+ hasCtor bool
98
+ decoratedMethodsOnly bool
99
+ }
100
+
101
+ type propertyInfo struct {
102
+ name string
103
+ typeText string
104
+ typeNode *shimast.Node
105
+ metadataText string
106
+ optional bool
107
+ }
108
+
109
+ type utilityProperty struct {
110
+ name string
111
+ typeText string
112
+ typeNode *shimast.Node
113
+ optional bool
114
+ owner *fileInfo
115
+ }
116
+
117
+ type methodInfo struct {
118
+ name string
119
+ description string
120
+ typeParams []string
121
+ returnType string
122
+ returnTypeNode *shimast.Node
123
+ returnMetadataText string
124
+ preferTypia bool
125
+ decorated bool
126
+ params []paramInfo
127
+ }
128
+
129
+ type functionInfo struct {
130
+ name string
131
+ owner string
132
+ typeParams []string
133
+ params []paramInfo
134
+ pos int
135
+ }
136
+
137
+ type paramInfo struct {
138
+ name string
139
+ typeText string
140
+ typeNode *shimast.Node
141
+ metadataText string
142
+ optional bool
143
+ hasDefault bool
144
+ }
145
+
146
+ type callInfo struct {
147
+ name string
148
+ nodePos int
149
+ metadataArgIndex int
150
+ typeText string
151
+ typeNode *shimast.Node
152
+ metadataText string
153
+ preferTypia bool
154
+ pos int
155
+ }
156
+
157
+ type typeContext struct {
158
+ seen map[string]bool
159
+ interfaces map[string]bool
160
+ typeParams map[string]bool
161
+ depth int
162
+ pos int
163
+ }
164
+
165
+ type hostOptions struct {
166
+ checkers int
167
+ cwd string
168
+ emit bool
169
+ noEmit bool
170
+ outDir string
171
+ pluginsJSON string
172
+ quiet bool
173
+ singleThreaded bool
174
+ tsconfig string
175
+ tsgoArgs []string
176
+ verbose bool
177
+ }
178
+
179
+ type pluginManifestEntry struct {
180
+ Name string `json:"name"`
181
+ Config json.RawMessage `json:"config"`
182
+ }
183
+
184
+ type typeCompilerPluginConfig struct {
185
+ EmitMetadataRuntimeImport *bool `json:"emitMetadataRuntimeImport"`
186
+ EmitTypeAliases *bool `json:"emitTypeAliases"`
187
+ EmitUndecoratedMethods *bool `json:"emitUndecoratedMethods"`
188
+ }
189
+
190
+ func main() {
191
+ if len(os.Args) < 2 {
192
+ fmt.Fprintln(os.Stderr, "tssf metadata host: expected command: build, check, or transform")
193
+ os.Exit(2)
194
+ }
195
+ switch os.Args[1] {
196
+ case "build", "check":
197
+ os.Exit(runBuild(os.Args[1], os.Args[2:]))
198
+ case "transform":
199
+ fmt.Fprintln(os.Stderr, "tssf metadata host: transform text output is not implemented in this POC")
200
+ os.Exit(2)
201
+ default:
202
+ fmt.Fprintf(os.Stderr, "tssf metadata host: unsupported command %q\n", os.Args[1])
203
+ os.Exit(2)
204
+ }
205
+ }
206
+
207
+ func runBuild(command string, args []string) int {
208
+ opts, ok := parseHostOptions(command, args)
209
+ if !ok {
210
+ return 2
211
+ }
212
+ if command == "check" {
213
+ opts.noEmit = true
214
+ }
215
+ if opts.verbose {
216
+ opts.quiet = false
217
+ }
218
+ prog, diags, err := driver.LoadProgram(opts.cwd, opts.tsconfig, driver.LoadProgramOptions{
219
+ ForceEmit: opts.emit,
220
+ ForceNoEmit: opts.noEmit,
221
+ OutDir: opts.outDir,
222
+ SingleThreaded: opts.singleThreaded,
223
+ Checkers: opts.checkers,
224
+ TsgoArgs: opts.tsgoArgs,
225
+ })
226
+ if err != nil {
227
+ fmt.Fprintf(os.Stderr, "tssf metadata host: %v\n", err)
228
+ return 2
229
+ }
230
+ if prog != nil {
231
+ defer prog.Close()
232
+ }
233
+ if len(diags) > 0 {
234
+ driver.WritePrettyDiagnostics(os.Stderr, diags, opts.cwd)
235
+ return 2
236
+ }
237
+ if prog == nil {
238
+ fmt.Fprintln(os.Stderr, "tssf metadata host: failed to load program")
239
+ return 2
240
+ }
241
+ if diags := prog.Diagnostics(); len(diags) > 0 {
242
+ driver.WritePrettyDiagnostics(os.Stderr, diags, opts.cwd)
243
+ return 2
244
+ }
245
+ if opts.noEmit {
246
+ return 0
247
+ }
248
+
249
+ if err := prog.ApplyLinkedPlugins(); err != nil {
250
+ fmt.Fprintf(os.Stderr, "tssf metadata host: apply linked plugins: %v\n", err)
251
+ return 2
252
+ }
253
+ pluginConfig := readTypeCompilerPluginConfig(opts.pluginsJSON)
254
+ emitMetadataRuntimeImport := pluginConfig.EmitMetadataRuntimeImport == nil || *pluginConfig.EmitMetadataRuntimeImport
255
+ emitTypeAliases := pluginConfig.EmitTypeAliases == nil || *pluginConfig.EmitTypeAliases
256
+ emitUndecoratedMethods := pluginConfig.EmitUndecoratedMethods == nil || *pluginConfig.EmitUndecoratedMethods
257
+ reg := collectRegistry(prog, opts.cwd, emitTypeAliases, emitUndecoratedMethods)
258
+ plans, err := buildEmissionPlans(reg, prog, emitTypeAliases, emitMetadataRuntimeImport)
259
+ if err != nil {
260
+ fmt.Fprintf(os.Stderr, "tssf metadata host: build emission plans: %v\n", err)
261
+ return 2
262
+ }
263
+ if !opts.quiet {
264
+ fmt.Fprintf(os.Stdout, "// tssf metadata host: files=%d classes=%d\n", len(reg.files), len(reg.classes))
265
+ }
266
+ emitDiags, err := prog.EmitWithPluginTransformers([]driver.PluginTransform{metadataTransform(plans)}, nil)
267
+ if err != nil {
268
+ fmt.Fprintf(os.Stderr, "tssf metadata host: emit: %v\n", err)
269
+ return 2
270
+ }
271
+ if len(emitDiags) > 0 {
272
+ driver.WritePrettyDiagnostics(os.Stderr, emitDiags, opts.cwd)
273
+ }
274
+ if driver.CountErrors(emitDiags) > 0 {
275
+ return 2
276
+ }
277
+ return 0
278
+ }
279
+
280
+ func shouldEmitTypeAliases(pluginsJSON string) bool {
281
+ config := readTypeCompilerPluginConfig(pluginsJSON)
282
+ return config.EmitTypeAliases == nil || *config.EmitTypeAliases
283
+ }
284
+
285
+ func readTypeCompilerPluginConfig(pluginsJSON string) typeCompilerPluginConfig {
286
+ if strings.TrimSpace(pluginsJSON) == "" {
287
+ return typeCompilerPluginConfig{}
288
+ }
289
+ var entries []pluginManifestEntry
290
+ if err := json.Unmarshal([]byte(pluginsJSON), &entries); err != nil {
291
+ return typeCompilerPluginConfig{}
292
+ }
293
+ for _, entry := range entries {
294
+ if entry.Name != "tsf-type-metadata" || len(entry.Config) == 0 {
295
+ continue
296
+ }
297
+ var config typeCompilerPluginConfig
298
+ if err := json.Unmarshal(entry.Config, &config); err == nil {
299
+ return config
300
+ }
301
+ }
302
+ return typeCompilerPluginConfig{}
303
+ }
304
+
305
+ func parseHostOptions(command string, args []string) (hostOptions, bool) {
306
+ fs := flag.NewFlagSet(command, flag.ContinueOnError)
307
+ fs.SetOutput(os.Stderr)
308
+ cwd := fs.String("cwd", "", "project directory")
309
+ emit := fs.Bool("emit", false, "force emit")
310
+ noEmit := fs.Bool("noEmit", false, "force no emit")
311
+ outDir := fs.String("outDir", "", "emit directory override")
312
+ pluginsJSON := fs.String("plugins-json", "", "ttsc plugin manifest JSON")
313
+ quiet := fs.Bool("quiet", true, "suppress summary")
314
+ tsconfig := fs.String("tsconfig", "tsconfig.json", "project tsconfig")
315
+ verbose := fs.Bool("verbose", false, "print summary")
316
+ singleThreaded := fs.Bool("singleThreaded", false, "run TypeScript-Go single-threaded")
317
+ checkers := fs.Int("checkers", 0, "type-checker pool size")
318
+ tsgoArgsRaw := fs.String("tsgo-args", "", "JSON array of forwarded tsgo flags")
319
+ if err := fs.Parse(args); err != nil {
320
+ return hostOptions{}, false
321
+ }
322
+ var tsgoArgs []string
323
+ if strings.TrimSpace(*tsgoArgsRaw) != "" {
324
+ if err := json.Unmarshal([]byte(*tsgoArgsRaw), &tsgoArgs); err != nil {
325
+ fmt.Fprintf(os.Stderr, "tssf metadata host: invalid --tsgo-args: %v\n", err)
326
+ return hostOptions{}, false
327
+ }
328
+ }
329
+ resolvedCwd := *cwd
330
+ if resolvedCwd == "" {
331
+ var err error
332
+ resolvedCwd, err = os.Getwd()
333
+ if err != nil {
334
+ fmt.Fprintf(os.Stderr, "tssf metadata host: cwd: %v\n", err)
335
+ return hostOptions{}, false
336
+ }
337
+ }
338
+ if !filepath.IsAbs(resolvedCwd) {
339
+ abs, err := filepath.Abs(resolvedCwd)
340
+ if err != nil {
341
+ fmt.Fprintf(os.Stderr, "tssf metadata host: cwd: %v\n", err)
342
+ return hostOptions{}, false
343
+ }
344
+ resolvedCwd = abs
345
+ }
346
+ return hostOptions{
347
+ checkers: *checkers,
348
+ cwd: filepath.Clean(resolvedCwd),
349
+ emit: *emit,
350
+ noEmit: *noEmit,
351
+ outDir: *outDir,
352
+ pluginsJSON: *pluginsJSON,
353
+ quiet: *quiet,
354
+ singleThreaded: *singleThreaded,
355
+ tsconfig: *tsconfig,
356
+ tsgoArgs: tsgoArgs,
357
+ verbose: *verbose,
358
+ }, true
359
+ }