typespec-rust-emitter 0.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 (43) hide show
  1. package/README.md +220 -0
  2. package/dist/src/emitter.d.ts +7 -0
  3. package/dist/src/emitter.js +490 -0
  4. package/dist/src/emitter.js.map +1 -0
  5. package/dist/src/index.d.ts +3 -0
  6. package/dist/src/index.js +4 -0
  7. package/dist/src/index.js.map +1 -0
  8. package/dist/src/lib.d.ts +12 -0
  9. package/dist/src/lib.js +7 -0
  10. package/dist/src/lib.js.map +1 -0
  11. package/dist/src/testing/index.d.ts +2 -0
  12. package/dist/src/testing/index.js +8 -0
  13. package/dist/src/testing/index.js.map +1 -0
  14. package/dist/test/hello.test.d.ts +1 -0
  15. package/dist/test/hello.test.js +140 -0
  16. package/dist/test/hello.test.js.map +1 -0
  17. package/dist/test/test-host.d.ts +4 -0
  18. package/dist/test/test-host.js +16 -0
  19. package/dist/test/test-host.js.map +1 -0
  20. package/eslint.config.js +20 -0
  21. package/example/lib/learning/models.tsp +189 -0
  22. package/example/lib/learning/operations.tsp +319 -0
  23. package/example/main.tsp +8 -0
  24. package/example/output-rust/Cargo.lock +1731 -0
  25. package/example/output-rust/Cargo.toml +12 -0
  26. package/example/output-rust/src/generated/mod.rs +1 -0
  27. package/example/output-rust/src/generated/types.rs +315 -0
  28. package/example/output-rust/src/main.rs +5 -0
  29. package/example/output-rust/src/mod.rs +1 -0
  30. package/example/package-lock.json +1495 -0
  31. package/example/package.json +15 -0
  32. package/example/tspconfig.yaml +10 -0
  33. package/justfile +15 -0
  34. package/package.json +64 -0
  35. package/prettierrc.yaml +8 -0
  36. package/src/emitter.ts +685 -0
  37. package/src/index.ts +3 -0
  38. package/src/lib.ts +8 -0
  39. package/src/lib.tsp +6 -0
  40. package/src/testing/index.ts +8 -0
  41. package/test/hello.test.ts +168 -0
  42. package/test/test-host.ts +20 -0
  43. package/tsconfig.json +18 -0
@@ -0,0 +1,12 @@
1
+ [package]
2
+ name = "output-rust"
3
+ version = "0.1.0"
4
+ edition = "2024"
5
+
6
+ [dependencies]
7
+ regex = "1.12.3"
8
+ serde = { version = "1.0.228", features = ["derive"] }
9
+ serde_json = "1.0.149"
10
+ thiserror = "2.0.18"
11
+ uuid = { version = "1.23.0", features = ["serde"] }
12
+ sqlx = { version = "0.8", features = ["runtime-tokio", "postgres", "derive"] }
@@ -0,0 +1 @@
1
+ mod types;
@@ -0,0 +1,315 @@
1
+ #[derive(Debug, Clone, serde::Serialize, serde::Deserialize, thiserror::Error)]
2
+ #[error("{code}: {message}")]
3
+ pub struct ApiError
4
+ {
5
+
6
+ /// Machine-readable error code.
7
+ pub code: String,
8
+
9
+ /// Human-readable message.
10
+ pub message: String,
11
+ }
12
+
13
+ #[derive(Debug, Clone, serde::Serialize, serde::Deserialize, thiserror::Error)]
14
+ #[error("{code}: {message}")]
15
+ pub struct NotFoundError
16
+ {
17
+ pub code: String,
18
+
19
+ /// Human-readable message.
20
+ pub message: String,
21
+ }
22
+
23
+ #[derive(Debug, Clone, serde::Serialize, serde::Deserialize, thiserror::Error)]
24
+ #[error("{code}: {message}")]
25
+ pub struct ValidationError
26
+ {
27
+ pub code: String,
28
+
29
+ /// Human-readable message.
30
+ pub message: String,
31
+ }
32
+
33
+ #[derive(Debug, Clone, serde::Serialize, serde::Deserialize, thiserror::Error)]
34
+ #[error("{code}: {message}")]
35
+ pub struct ConflictError
36
+ {
37
+ pub code: String,
38
+
39
+ /// Human-readable message.
40
+ pub message: String,
41
+ }
42
+
43
+ #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
44
+ pub struct DurationStats
45
+ {
46
+ #[serde(rename = "durationTotal")]
47
+ pub duration_total: i64,
48
+ #[serde(rename = "durationDay")]
49
+ pub duration_day: i64,
50
+ #[serde(rename = "durationWeek")]
51
+ pub duration_week: i64,
52
+ #[serde(rename = "durationMonth")]
53
+ pub duration_month: i64,
54
+ }
55
+
56
+ #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
57
+ pub struct Group
58
+ {
59
+ pub id: i64,
60
+ #[serde(rename = "accountId")]
61
+ pub account_id: uuid::Uuid,
62
+ #[serde(rename = "createdAt")]
63
+ pub created_at: String,
64
+ #[serde(rename = "deletedAt")]
65
+ pub deleted_at: Option<String>,
66
+ pub name: String,
67
+ pub icon: String,
68
+ #[serde(rename = "colorText")]
69
+ pub color_text: HexColor,
70
+ #[serde(rename = "colorBg")]
71
+ pub color_bg: HexColor,
72
+ }
73
+
74
+ #[derive(Debug, Clone, serde::Serialize, serde::Deserialize, sqlx::FromRow)]
75
+ pub struct GroupStatistics
76
+ {
77
+ pub id: i64,
78
+ #[serde(rename = "accountId")]
79
+ pub account_id: uuid::Uuid,
80
+ #[serde(rename = "createdAt")]
81
+ pub created_at: String,
82
+ #[serde(rename = "deletedAt")]
83
+ pub deleted_at: Option<String>,
84
+ pub name: String,
85
+ pub icon: String,
86
+ #[serde(rename = "colorText")]
87
+ pub color_text: HexColor,
88
+ #[serde(rename = "colorBg")]
89
+ pub color_bg: HexColor,
90
+ #[serde(rename = "subjectCount")]
91
+ pub subject_count: i64,
92
+ pub status: StudyStatus,
93
+ #[serde(rename = "durationTotal")]
94
+ pub duration_total: i64,
95
+ #[serde(rename = "durationDay")]
96
+ pub duration_day: i64,
97
+ #[serde(rename = "durationWeek")]
98
+ pub duration_week: i64,
99
+ #[serde(rename = "durationMonth")]
100
+ pub duration_month: i64,
101
+ }
102
+
103
+ #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
104
+ pub struct CreateGroupBody
105
+ {
106
+ pub name: String,
107
+ pub icon: String,
108
+ #[serde(rename = "colorText")]
109
+ pub color_text: HexColor,
110
+ #[serde(rename = "colorBg")]
111
+ pub color_bg: HexColor,
112
+ }
113
+
114
+ #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
115
+ pub struct UpdateGroupBody
116
+ {
117
+ #[serde(skip_serializing_if = "Option::is_none")]
118
+ pub name: Option<String>,
119
+ #[serde(skip_serializing_if = "Option::is_none")]
120
+ pub icon: Option<String>,
121
+ #[serde(rename = "colorText")]
122
+ #[serde(skip_serializing_if = "Option::is_none")]
123
+ pub color_text: Option<HexColor>,
124
+ #[serde(rename = "colorBg")]
125
+ #[serde(skip_serializing_if = "Option::is_none")]
126
+ pub color_bg: Option<HexColor>,
127
+ }
128
+
129
+ #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
130
+ pub struct Subject
131
+ {
132
+ pub id: i64,
133
+ #[serde(rename = "accountId")]
134
+ pub account_id: uuid::Uuid,
135
+ #[serde(rename = "groupId")]
136
+ pub group_id: i64,
137
+ #[serde(rename = "createdAt")]
138
+ pub created_at: String,
139
+ #[serde(rename = "deletedAt")]
140
+ pub deleted_at: Option<String>,
141
+ pub name: String,
142
+ pub icon: String,
143
+ #[serde(rename = "colorText")]
144
+ pub color_text: HexColor,
145
+ #[serde(rename = "colorBg")]
146
+ pub color_bg: HexColor,
147
+ }
148
+
149
+ #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
150
+ pub struct SubjectStatistics
151
+ {
152
+ pub id: i64,
153
+ #[serde(rename = "accountId")]
154
+ pub account_id: uuid::Uuid,
155
+ #[serde(rename = "groupId")]
156
+ pub group_id: i64,
157
+ #[serde(rename = "createdAt")]
158
+ pub created_at: String,
159
+ #[serde(rename = "deletedAt")]
160
+ pub deleted_at: Option<String>,
161
+ pub name: String,
162
+ pub icon: String,
163
+ #[serde(rename = "colorText")]
164
+ pub color_text: HexColor,
165
+ #[serde(rename = "colorBg")]
166
+ pub color_bg: HexColor,
167
+ pub status: StudyStatus,
168
+ #[serde(rename = "durationTotal")]
169
+ pub duration_total: i64,
170
+ #[serde(rename = "durationDay")]
171
+ pub duration_day: i64,
172
+ #[serde(rename = "durationWeek")]
173
+ pub duration_week: i64,
174
+ #[serde(rename = "durationMonth")]
175
+ pub duration_month: i64,
176
+ }
177
+
178
+ #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
179
+ pub struct CreateSubjectBody
180
+ {
181
+ pub name: String,
182
+ pub icon: String,
183
+ #[serde(rename = "colorText")]
184
+ pub color_text: HexColor,
185
+ #[serde(rename = "colorBg")]
186
+ pub color_bg: HexColor,
187
+ }
188
+
189
+ #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
190
+ pub struct UpdateSubjectBody
191
+ {
192
+ #[serde(skip_serializing_if = "Option::is_none")]
193
+ pub name: Option<String>,
194
+ #[serde(skip_serializing_if = "Option::is_none")]
195
+ pub icon: Option<String>,
196
+ #[serde(rename = "colorText")]
197
+ #[serde(skip_serializing_if = "Option::is_none")]
198
+ pub color_text: Option<HexColor>,
199
+ #[serde(rename = "colorBg")]
200
+ #[serde(skip_serializing_if = "Option::is_none")]
201
+ pub color_bg: Option<HexColor>,
202
+ }
203
+
204
+ #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
205
+ pub struct Log
206
+ {
207
+ pub id: i64,
208
+ #[serde(rename = "accountId")]
209
+ pub account_id: uuid::Uuid,
210
+ #[serde(rename = "subjectId")]
211
+ pub subject_id: i64,
212
+ #[serde(rename = "startedAt")]
213
+ pub started_at: String,
214
+ #[serde(rename = "stoppedAt")]
215
+ pub stopped_at: Option<String>,
216
+ #[serde(rename = "logContent")]
217
+ pub log_content: Option<String>,
218
+ pub status: StudyStatus,
219
+ }
220
+
221
+ #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
222
+ pub struct Timelog
223
+ {
224
+ pub id: i64,
225
+ #[serde(rename = "accountId")]
226
+ pub account_id: uuid::Uuid,
227
+ #[serde(rename = "logId")]
228
+ pub log_id: i64,
229
+ #[serde(rename = "subjectId")]
230
+ pub subject_id: i64,
231
+ #[serde(rename = "startedAt")]
232
+ pub started_at: String,
233
+ #[serde(rename = "stoppedAt")]
234
+ pub stopped_at: Option<String>,
235
+ #[serde(rename = "durationInSeconds")]
236
+ pub duration_in_seconds: i64,
237
+ }
238
+
239
+ #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
240
+ pub struct SessionOpenedResponse
241
+ {
242
+ pub log: Log,
243
+ pub timelog: Timelog,
244
+ }
245
+
246
+ #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
247
+ pub struct SessionClosedResponse
248
+ {
249
+ pub log: Log,
250
+ pub timelog: Timelog,
251
+ }
252
+
253
+ #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
254
+ pub struct SessionNoteBody
255
+ {
256
+ #[serde(rename = "logContent")]
257
+ #[serde(skip_serializing_if = "Option::is_none")]
258
+ pub log_content: Option<String>,
259
+ }
260
+
261
+ #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
262
+ pub enum StudyStatus {
263
+ #[serde(rename = "Starting")]
264
+ Starting,
265
+ #[serde(rename = "Paused")]
266
+ Paused,
267
+ #[serde(rename = "Stopped")]
268
+ Stopped,
269
+ }
270
+
271
+
272
+ impl Default for StudyStatus {
273
+ fn default() -> Self {
274
+ StudyStatus::Starting
275
+ }
276
+ }
277
+
278
+ #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
279
+ pub enum ChartGranularity {
280
+ #[serde(rename = "day")]
281
+ Day,
282
+ #[serde(rename = "week")]
283
+ Week,
284
+ #[serde(rename = "month")]
285
+ Month,
286
+ #[serde(rename = "year")]
287
+ Year,
288
+ }
289
+
290
+
291
+ impl Default for ChartGranularity {
292
+ fn default() -> Self {
293
+ ChartGranularity::Day
294
+ }
295
+ }
296
+
297
+ pub type Uuid = uuid::Uuid;
298
+
299
+ #[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
300
+ pub struct HexColor(pub String);
301
+
302
+ impl TryFrom<String> for HexColor {
303
+ type Error = String;
304
+
305
+ fn try_from(value: String) -> Result<Self, Self::Error> {
306
+ let re = regex::Regex::new(r"^#[0-9A-Fa-f]{6}$").unwrap();
307
+ if re.is_match(&value) { Ok(Self(value)) } else { Err(format!("Invalid value: {}", value)) }
308
+ }
309
+ }
310
+
311
+ impl Default for HexColor {
312
+ fn default() -> Self {
313
+ Self(String::new())
314
+ }
315
+ }
@@ -0,0 +1,5 @@
1
+ mod generated;
2
+
3
+ fn main() {
4
+ println!("Hello, world!");
5
+ }
@@ -0,0 +1 @@
1
+ mod generated;