nautilus_codegen/js/
backend.rs1use nautilus_schema::ir::ScalarType;
4
5use crate::backend::LanguageBackend;
6
7pub struct JsBackend;
9
10impl LanguageBackend for JsBackend {
11 fn scalar_to_type(&self, scalar: &ScalarType) -> &'static str {
12 match scalar {
13 ScalarType::String => "string",
14 ScalarType::Int => "number",
15 ScalarType::BigInt => "number",
16 ScalarType::Float => "number",
17 ScalarType::Decimal { .. } => "string", ScalarType::Boolean => "boolean",
19 ScalarType::DateTime => "Date",
20 ScalarType::Bytes => "Buffer",
21 ScalarType::Json => "Record<string, unknown>",
22 ScalarType::Uuid => "string",
23 ScalarType::Jsonb => "Record<string, unknown>",
24 ScalarType::Xml | ScalarType::Char { .. } | ScalarType::VarChar { .. } => "string",
25 }
26 }
27
28 fn array_type(&self, inner: &str) -> String {
29 format!("{}[]", inner)
30 }
31
32 fn not_in_suffix(&self) -> &'static str {
33 "notIn"
34 }
35
36 fn startswith_suffix(&self) -> &'static str {
37 "startsWith"
38 }
39
40 fn endswith_suffix(&self) -> &'static str {
41 "endsWith"
42 }
43
44 fn null_suffix(&self) -> &'static str {
45 "isNull"
46 }
47
48 fn null_literal(&self) -> &'static str {
49 "null"
50 }
51
52 fn true_literal(&self) -> &'static str {
53 "true"
54 }
55
56 fn false_literal(&self) -> &'static str {
57 "false"
58 }
59
60 fn string_literal(&self, s: &str) -> String {
61 format!("'{}'", s)
62 }
63
64 fn empty_array_literal(&self) -> &'static str {
65 "[]"
66 }
67
68 fn enum_variant_literal(&self, variant: &str) -> String {
69 format!("'{}'", variant)
70 }
71
72 fn relation_type(&self, target_model: &str) -> String {
73 format!("{}Model", target_model)
74 }
75}