@typra/emitter 0.2.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 (82) hide show
  1. package/dist/src/cleanup/generated-file.d.ts +6 -0
  2. package/dist/src/cleanup/generated-file.js +61 -0
  3. package/dist/src/cli.d.ts +2 -0
  4. package/dist/src/cli.js +110 -0
  5. package/dist/src/decorators.d.ts +56 -0
  6. package/dist/src/decorators.js +177 -0
  7. package/dist/src/emitter.d.ts +13 -0
  8. package/dist/src/emitter.js +137 -0
  9. package/dist/src/generate.d.ts +86 -0
  10. package/dist/src/generate.js +104 -0
  11. package/dist/src/index.d.ts +4 -0
  12. package/dist/src/index.js +5 -0
  13. package/dist/src/ir/ast.d.ts +235 -0
  14. package/dist/src/ir/ast.js +589 -0
  15. package/dist/src/ir/declarations.d.ts +364 -0
  16. package/dist/src/ir/declarations.js +23 -0
  17. package/dist/src/ir/expansion.d.ts +140 -0
  18. package/dist/src/ir/expansion.js +407 -0
  19. package/dist/src/ir/lower.d.ts +53 -0
  20. package/dist/src/ir/lower.js +480 -0
  21. package/dist/src/ir/utilities.d.ts +12 -0
  22. package/dist/src/ir/utilities.js +39 -0
  23. package/dist/src/ir/visitor.d.ts +29 -0
  24. package/dist/src/ir/visitor.js +48 -0
  25. package/dist/src/languages/csharp/driver.d.ts +5 -0
  26. package/dist/src/languages/csharp/driver.js +315 -0
  27. package/dist/src/languages/csharp/emitter.d.ts +33 -0
  28. package/dist/src/languages/csharp/emitter.js +1140 -0
  29. package/dist/src/languages/csharp/scaffolding.d.ts +18 -0
  30. package/dist/src/languages/csharp/scaffolding.js +591 -0
  31. package/dist/src/languages/csharp/test-emitter.d.ts +43 -0
  32. package/dist/src/languages/csharp/test-emitter.js +274 -0
  33. package/dist/src/languages/csharp/visitor.d.ts +14 -0
  34. package/dist/src/languages/csharp/visitor.js +79 -0
  35. package/dist/src/languages/go/driver.d.ts +12 -0
  36. package/dist/src/languages/go/driver.js +128 -0
  37. package/dist/src/languages/go/emitter.d.ts +33 -0
  38. package/dist/src/languages/go/emitter.js +879 -0
  39. package/dist/src/languages/go/scaffolding.d.ts +18 -0
  40. package/dist/src/languages/go/scaffolding.js +53 -0
  41. package/dist/src/languages/go/test-emitter.d.ts +20 -0
  42. package/dist/src/languages/go/test-emitter.js +300 -0
  43. package/dist/src/languages/go/visitor.d.ts +14 -0
  44. package/dist/src/languages/go/visitor.js +78 -0
  45. package/dist/src/languages/markdown/driver.d.ts +19 -0
  46. package/dist/src/languages/markdown/driver.js +408 -0
  47. package/dist/src/languages/python/driver.d.ts +14 -0
  48. package/dist/src/languages/python/driver.js +372 -0
  49. package/dist/src/languages/python/emitter.d.ts +31 -0
  50. package/dist/src/languages/python/emitter.js +856 -0
  51. package/dist/src/languages/python/scaffolding.d.ts +33 -0
  52. package/dist/src/languages/python/scaffolding.js +279 -0
  53. package/dist/src/languages/python/test-emitter.d.ts +29 -0
  54. package/dist/src/languages/python/test-emitter.js +388 -0
  55. package/dist/src/languages/python/visitor.d.ts +14 -0
  56. package/dist/src/languages/python/visitor.js +65 -0
  57. package/dist/src/languages/rust/driver.d.ts +13 -0
  58. package/dist/src/languages/rust/driver.js +624 -0
  59. package/dist/src/languages/rust/emitter.d.ts +45 -0
  60. package/dist/src/languages/rust/emitter.js +1596 -0
  61. package/dist/src/languages/rust/visitor.d.ts +25 -0
  62. package/dist/src/languages/rust/visitor.js +153 -0
  63. package/dist/src/languages/typescript/driver.d.ts +8 -0
  64. package/dist/src/languages/typescript/driver.js +209 -0
  65. package/dist/src/languages/typescript/emitter.d.ts +42 -0
  66. package/dist/src/languages/typescript/emitter.js +904 -0
  67. package/dist/src/languages/typescript/scaffolding.d.ts +32 -0
  68. package/dist/src/languages/typescript/scaffolding.js +303 -0
  69. package/dist/src/languages/typescript/test-emitter.d.ts +23 -0
  70. package/dist/src/languages/typescript/test-emitter.js +204 -0
  71. package/dist/src/languages/typescript/visitor.d.ts +14 -0
  72. package/dist/src/languages/typescript/visitor.js +64 -0
  73. package/dist/src/lib.d.ts +33 -0
  74. package/dist/src/lib.js +101 -0
  75. package/dist/src/testing/index.d.ts +2 -0
  76. package/dist/src/testing/index.js +8 -0
  77. package/dist/src/testing/test-context.d.ts +63 -0
  78. package/dist/src/testing/test-context.js +355 -0
  79. package/fixtures/shapes/main.tsp +43 -0
  80. package/fixtures/tspconfig.yaml +13 -0
  81. package/package.json +76 -0
  82. package/src/lib/main.tsp +110 -0
@@ -0,0 +1,110 @@
1
+ import "../../dist/src/decorators.js";
2
+ using TypeSpec.Reflection;
3
+
4
+ /**
5
+ * Adds a sample to the target model property.
6
+ */
7
+ extern dec sample(target: ModelProperty, sample: valueof unknown);
8
+
9
+ /**
10
+ * Marks the target model as abstract, preventing direct instantiation.
11
+ */
12
+ extern dec abstract(target: Model);
13
+
14
+ /**
15
+ * Marks the target model as having a scalar-to-object implicit conversion.
16
+ * When a scalar value is encountered during deserialization, it is expanded
17
+ * into a full object using the provided expansion template.
18
+ */
19
+ extern dec coerce(
20
+ target: Model,
21
+ `scalar`: Scalar,
22
+ expansion: valueof unknown,
23
+ title?: valueof string,
24
+ description?: valueof string,
25
+ example?: valueof unknown
26
+ );
27
+
28
+ /**
29
+ * Declares a factory method on the target model. Factory methods are fully
30
+ * generated — the emitter produces both signature and body. The `sets` parameter
31
+ * specifies which fields to assign and their values. The optional `params`
32
+ * parameter specifies method parameters (name → type string).
33
+ *
34
+ * @example
35
+ * ```typespec
36
+ * @@factory("allow", #{ allowed: true })
37
+ * @@factory("deny", #{ allowed: false }, #{ reason: "string" })
38
+ * ```
39
+ */
40
+ extern dec factory(
41
+ target: Model,
42
+ name: valueof string,
43
+ sets: valueof unknown,
44
+ params?: valueof unknown
45
+ );
46
+
47
+ /**
48
+ * Declares a method stub on the target model. Method stubs are
49
+ * stub-generated — the emitter produces the signature in the generated file
50
+ * and a create-if-missing extension file where the body must be hand-written.
51
+ * This enforces that every runtime implements the method (compile/test failure
52
+ * if missing) while allowing language-idiomatic implementations.
53
+ *
54
+ * The optional `params` parameter specifies method parameters (name → type string).
55
+ * When used on `@protocol` models, params drive the generated interface method
56
+ * signatures.
57
+ *
58
+ * @example
59
+ * ```typespec
60
+ * @@method("text", "string", "Concatenate all TextPart values joined by newline")
61
+ * @@method("render", "string", "Render template with inputs", #{ agent: "Prompty", template: "string", inputs: "Record<unknown>" })
62
+ * ```
63
+ */
64
+ extern dec method(
65
+ target: Model,
66
+ name: valueof string,
67
+ returns: valueof string,
68
+ description?: valueof string,
69
+ params?: valueof unknown,
70
+ optional?: valueof boolean,
71
+ sync?: valueof boolean
72
+ );
73
+
74
+ /**
75
+ * Maps a property's wire name for a specific provider. Used in provider
76
+ * wire.tsp files via augment syntax (`@@`) to declare how core property names
77
+ * map to provider-specific API parameter names.
78
+ *
79
+ * @param provider The target provider identifier (e.g., "openai", "anthropic")
80
+ * @param name The wire field name used by that provider's API
81
+ *
82
+ * @example
83
+ * ```typespec
84
+ * @@knownAs(ModelOptions.maxOutputTokens, "openai", "max_completion_tokens")
85
+ * @@knownAs(ModelOptions.maxOutputTokens, "anthropic", "max_tokens")
86
+ * ```
87
+ */
88
+ extern dec knownAs(target: ModelProperty, provider: valueof string, name: valueof string);
89
+
90
+ /**
91
+ * Declares a per-provider required default value for a property. Used in provider
92
+ * wire.tsp files via augment syntax (`@@`) when a provider requires a value that
93
+ * the core schema treats as optional.
94
+ *
95
+ * @param provider The target provider identifier (e.g., "openai", "anthropic")
96
+ * @param defaultValue The default value for that provider
97
+ *
98
+ * @example
99
+ * ```typespec
100
+ * @@defaultFor(ModelOptions.maxOutputTokens, "openai", 4096)
101
+ * ```
102
+ */
103
+ extern dec defaultFor(target: ModelProperty, provider: valueof string, defaultValue: valueof unknown);
104
+
105
+ /**
106
+ * Marks the target model as a protocol interface. Protocol interfaces define
107
+ * the pipeline stage contracts (renderer, parser, executor, processor). The
108
+ * emitter generates language-appropriate interface/trait/protocol definitions.
109
+ */
110
+ extern dec protocol(target: Model);