1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//! Turning the artifact into files an application's frontend can compile
//! against.
//!
//! Each generator is a pure function from the artifact to a `String`. File
//! IO belongs to the CLI, which knows where `resources/js/generated/` is
//! and whether the directory is gitignored; a generator that wrote its own
//! files could not be tested without a temp directory and could not be
//! reused by the dev server, which serves the same bytes over HTTP.
//!
//! The output has **no imports and no npm dependency**. Everything the
//! generated TypeScript needs is in the generated TypeScript. That is the
//! whole design: an application adds a directory to `.gitignore`, and its
//! editor, `tsc`, and Vite understand the result with no plugin, no virtual
//! module, and no package to publish or version.
//!
//! * [`type_map`] -- the single Rust -> TypeScript / JSON Schema mapping.
//! * [`routes_ts`] -- `routes.ts`, the typed route table and `route()`.
//! * [`pages_dts`] -- `pages.d.ts`, per-page prop types.
//! * [`forms_ts`] -- `forms.ts`, field names and validation rules.
//! * [`index_ts`] -- `index.ts`, the barrel `@/generated` resolves to.
//! * [`openapi`] -- the OpenAPI 3.1 document.
/// The banner every generated TypeScript file opens with.
///
/// Named after the command rather than the crate: the reader's next action
/// is to re-run something, not to find out which library wrote the file.
pub const GENERATED_HEADER: &str = "\
// Generated by `arc typegen` from the Arcature application graph.
// Do not edit -- this file is overwritten on the next run.
";
/// Renders a string as a TypeScript double-quoted literal.
///
/// Route names, paths, and field names all originate in Rust source, so a
/// quote or a backslash is unlikely -- but a generator that emits
/// syntactically broken TypeScript for one odd character is worse than one
/// that escapes unconditionally.