1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3
4use crate::{dmmf::Document, typed_sql::SqlQueryOutput};
5
6#[derive(Debug, Clone, Deserialize, Serialize)]
7#[serde(rename_all = "camelCase")]
8pub struct EnvValue {
9 pub from_env_var: Option<String>,
10 pub value: Option<String>,
11}
12
13#[derive(Debug, Clone, Deserialize, Serialize)]
14#[serde(rename_all = "camelCase")]
15pub struct BinaryTargetsEnvValue {
16 pub from_env_var: Option<String>,
17 pub value: String,
18 pub native: Option<bool>,
19}
20
21#[derive(Debug, Clone, Deserialize, Serialize)]
22#[serde(rename_all = "camelCase")]
23pub struct GeneratorConfig {
24 pub name: String,
25 pub output: Option<EnvValue>,
26 pub is_custom_output: Option<bool>,
27 pub provider: EnvValue,
28 pub config: HashMap<String, Option<String>>,
29 pub binary_targets: Vec<BinaryTargetsEnvValue>,
30 pub preview_features: Vec<String>,
31 pub env_paths: Option<EnvPaths>,
32 pub source_file_path: String,
33}
34
35#[derive(Debug, Clone, Deserialize, Serialize)]
36#[serde(rename_all = "camelCase")]
37pub struct EnvPaths {
38 pub root_env_path: Option<String>,
39 pub schema_env_path: Option<String>,
40}
41
42#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
43#[serde(rename_all = "lowercase")]
44pub enum ConnectorType {
45 Mysql,
46 Mongodb,
47 Sqlite,
48 Postgresql,
49 Postgres,
50 #[serde(rename = "prisma+postgres")]
51 PrismaPostgres,
53 Sqlserver,
54 Cockroachdb,
55}
56
57#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
58#[serde(rename_all = "lowercase")]
59pub enum ActiveConnectorType {
60 Mysql,
61 Mongodb,
62 Sqlite,
63 Postgresql,
64 Sqlserver,
65 Cockroachdb,
66}
67
68#[derive(Debug, Clone, Deserialize, Serialize)]
69#[serde(rename_all = "camelCase")]
70pub struct DataSource {
71 pub name: String,
72 pub provider: ConnectorType,
73 pub active_provider: ActiveConnectorType,
74 pub url: EnvValue,
75 pub direct_url: Option<EnvValue>,
76 pub schemas: Vec<String>,
77 pub source_file_path: String,
78}
79
80#[derive(Debug, Clone, Deserialize, Serialize)]
81#[serde(rename_all = "camelCase")]
82pub struct BinaryPaths {
83 pub schema_engine: Option<HashMap<String, String>>,
85 pub query_engine: Option<HashMap<String, String>>,
86 pub libquery_engine: Option<HashMap<String, String>>,
87}
88
89#[derive(Debug, Clone, Deserialize, Serialize)]
90#[serde(rename_all = "camelCase")]
91pub struct GeneratorOptions {
92 pub generator: GeneratorConfig,
93 pub other_generators: Vec<GeneratorConfig>,
94 pub schema_path: String,
95 pub dmmf: Document,
96 pub datasources: Vec<DataSource>,
97 pub datamodel: String,
98 pub version: String,
100 pub binary_paths: Option<BinaryPaths>,
101 pub postinstall: Option<bool>,
102 pub no_engine: Option<bool>,
103 pub no_hints: Option<bool>,
104 pub allow_no_models: Option<bool>,
105 pub env_paths: Option<EnvPaths>,
106 pub typed_sql: Option<Vec<SqlQueryOutput>>,
107}
108
109#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
110#[serde(rename_all = "camelCase")]
111#[allow(clippy::enum_variant_names)]
112pub enum EngineType {
113 QueryEngine,
114 LibqueryEngine,
115 SchemaEngine,
116}
117
118#[derive(Debug, Clone, Deserialize, Serialize)]
119#[serde(rename_all = "camelCase")]
120pub struct GeneratorManifest {
121 pub pretty_name: Option<String>,
122 pub default_output: Option<String>,
123 pub denylists: Option<DenyLists>,
124 pub requires_generators: Option<Vec<String>>,
125 pub requires_engines: Option<Vec<EngineType>>,
126 pub version: Option<String>,
127 pub requires_engine_version: Option<String>,
128}
129
130#[derive(Debug, Clone, Deserialize, Serialize)]
131pub struct DenyLists {
132 pub models: Option<Vec<String>>,
133 pub fields: Option<Vec<String>>,
134}