From a98377e9acc50457fbd88354b9f45d644925d162 Mon Sep 17 00:00:00 2001 From: Alberto Schiabel Date: Thu, 11 Jan 2024 11:42:28 +0100 Subject: [PATCH] feat(psl): moved psl-builtin-connectors within psl-core (#4630) --- Cargo.lock | 17 +------------- psl/builtin-connectors/Cargo.toml | 17 -------------- psl/psl-core/Cargo.toml | 1 + .../cockroach_datamodel_connector.rs | 22 +++++++++---------- .../native_types.rs | 0 .../validations.rs | 2 +- .../src/builtin_connectors}/completions.rs | 2 +- .../src/builtin_connectors/mod.rs} | 5 +---- .../src/builtin_connectors}/mongodb.rs | 8 +++---- .../mongodb/mongodb_types.rs | 2 +- .../mongodb/validations.rs | 4 ++-- .../mssql_datamodel_connector.rs | 10 ++++----- .../mssql_datamodel_connector/native_types.rs | 2 +- .../mssql_datamodel_connector/validations.rs | 2 +- .../mysql_datamodel_connector.rs | 10 ++++----- .../mysql_datamodel_connector/native_types.rs | 0 .../mysql_datamodel_connector/validations.rs | 14 +++++++----- .../native_type_definition.rs | 22 +++++++++---------- .../postgres_datamodel_connector.rs | 20 ++++++++--------- .../datasource.rs | 5 ++--- .../native_types.rs | 0 .../validations.rs | 6 ++--- .../sqlite_datamodel_connector.rs | 4 ++-- .../src/builtin_connectors}/utils.rs | 0 psl/psl-core/src/lib.rs | 1 + psl/psl/Cargo.toml | 1 - psl/psl/src/lib.rs | 2 +- psl/psl/tests/config/datasources.rs | 2 +- 28 files changed, 74 insertions(+), 107 deletions(-) delete mode 100644 psl/builtin-connectors/Cargo.toml rename psl/{builtin-connectors/src => psl-core/src/builtin_connectors}/cockroach_datamodel_connector.rs (96%) rename psl/{builtin-connectors/src => psl-core/src/builtin_connectors}/cockroach_datamodel_connector/native_types.rs (100%) rename psl/{builtin-connectors/src => psl-core/src/builtin_connectors}/cockroach_datamodel_connector/validations.rs (99%) rename psl/{builtin-connectors/src => psl-core/src/builtin_connectors}/completions.rs (96%) rename psl/{builtin-connectors/src/lib.rs => psl-core/src/builtin_connectors/mod.rs} (88%) rename psl/{builtin-connectors/src => psl-core/src/builtin_connectors}/mongodb.rs (98%) rename psl/{builtin-connectors/src => psl-core/src/builtin_connectors}/mongodb/mongodb_types.rs (97%) rename psl/{builtin-connectors/src => psl-core/src/builtin_connectors}/mongodb/validations.rs (99%) rename psl/{builtin-connectors/src => psl-core/src/builtin_connectors}/mssql_datamodel_connector.rs (98%) rename psl/{builtin-connectors/src => psl-core/src/builtin_connectors}/mssql_datamodel_connector/native_types.rs (97%) rename psl/{builtin-connectors/src => psl-core/src/builtin_connectors}/mssql_datamodel_connector/validations.rs (99%) rename psl/{builtin-connectors/src => psl-core/src/builtin_connectors}/mysql_datamodel_connector.rs (98%) rename psl/{builtin-connectors/src => psl-core/src/builtin_connectors}/mysql_datamodel_connector/native_types.rs (100%) rename psl/{builtin-connectors/src => psl-core/src/builtin_connectors}/mysql_datamodel_connector/validations.rs (94%) rename psl/{builtin-connectors/src => psl-core/src/builtin_connectors}/native_type_definition.rs (85%) rename psl/{builtin-connectors/src => psl-core/src/builtin_connectors}/postgres_datamodel_connector.rs (98%) rename psl/{builtin-connectors/src => psl-core/src/builtin_connectors}/postgres_datamodel_connector/datasource.rs (96%) rename psl/{builtin-connectors/src => psl-core/src/builtin_connectors}/postgres_datamodel_connector/native_types.rs (100%) rename psl/{builtin-connectors/src => psl-core/src/builtin_connectors}/postgres_datamodel_connector/validations.rs (99%) rename psl/{builtin-connectors/src => psl-core/src/builtin_connectors}/sqlite_datamodel_connector.rs (99%) rename psl/{builtin-connectors/src => psl-core/src/builtin_connectors}/utils.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 81573585da18..6fb116734862 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -428,21 +428,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "builtin-psl-connectors" -version = "0.1.0" -dependencies = [ - "chrono", - "connection-string", - "either", - "enumflags2", - "indoc 2.0.3", - "lsp-types", - "once_cell", - "psl-core", - "regex", -] - [[package]] name = "bumpalo" version = "3.13.0" @@ -3496,7 +3481,6 @@ name = "psl" version = "0.1.0" dependencies = [ "base64 0.13.1", - "builtin-psl-connectors", "dissimilar", "either", "expect-test", @@ -3512,6 +3496,7 @@ dependencies = [ "chrono", "connection-string", "diagnostics", + "either", "enumflags2", "indoc 2.0.3", "itertools 0.12.0", diff --git a/psl/builtin-connectors/Cargo.toml b/psl/builtin-connectors/Cargo.toml deleted file mode 100644 index ef9e810b8aba..000000000000 --- a/psl/builtin-connectors/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[package] -name = "builtin-psl-connectors" -version = "0.1.0" -edition = "2021" - -[dependencies] -psl-core = { path = "../psl-core" } - -connection-string.workspace = true -either = "1.6.1" -enumflags2 = "0.7" -indoc.workspace = true -lsp-types = "0.91.1" -once_cell = "1.3" -regex = "1" -chrono = { version = "0.4.6", default-features = false } - diff --git a/psl/psl-core/Cargo.toml b/psl/psl-core/Cargo.toml index f6584380de35..97f4dd56d470 100644 --- a/psl/psl-core/Cargo.toml +++ b/psl/psl-core/Cargo.toml @@ -19,6 +19,7 @@ serde.workspace = true serde_json.workspace = true enumflags2 = "0.7" indoc.workspace = true +either = "1.8.1" # For the connector API. lsp-types = "0.91.1" diff --git a/psl/builtin-connectors/src/cockroach_datamodel_connector.rs b/psl/psl-core/src/builtin_connectors/cockroach_datamodel_connector.rs similarity index 96% rename from psl/builtin-connectors/src/cockroach_datamodel_connector.rs rename to psl/psl-core/src/builtin_connectors/cockroach_datamodel_connector.rs index 99f94c953971..eec50a4bb9c1 100644 --- a/psl/builtin-connectors/src/cockroach_datamodel_connector.rs +++ b/psl/psl-core/src/builtin_connectors/cockroach_datamodel_connector.rs @@ -3,10 +3,7 @@ mod validations; pub use native_types::CockroachType; -use chrono::*; -use enumflags2::BitFlags; -use lsp_types::{CompletionItem, CompletionItemKind, CompletionList}; -use psl_core::{ +use crate::{ datamodel_connector::{ Connector, ConnectorCapabilities, ConnectorCapability, ConstraintScope, Flavour, NativeTypeConstructor, NativeTypeInstance, RelationMode, StringFilter, @@ -21,9 +18,12 @@ use psl_core::{ }, PreviewFeature, }; +use chrono::*; +use enumflags2::BitFlags; +use lsp_types::{CompletionItem, CompletionItemKind, CompletionList}; use std::borrow::Cow; -use crate::completions; +use super::completions; const CONSTRAINT_SCOPES: &[ConstraintScope] = &[ConstraintScope::ModelPrimaryKeyKeyIndexForeignKey]; @@ -294,7 +294,7 @@ impl Connector for CockroachDatamodelConnector { } } - fn datasource_completions(&self, config: &psl_core::Configuration, completion_list: &mut CompletionList) { + fn datasource_completions(&self, config: &crate::Configuration, completion_list: &mut CompletionList) { let ds = match config.datasources.first() { Some(ds) => ds, None => return, @@ -318,11 +318,11 @@ impl Connector for CockroachDatamodelConnector { match native_type { Some(ct) => match ct { - CockroachType::Timestamptz(_) => crate::utils::parse_timestamptz(str), - CockroachType::Timestamp(_) => crate::utils::parse_timestamp(str), - CockroachType::Date => crate::utils::parse_date(str), - CockroachType::Time(_) => crate::utils::parse_time(str), - CockroachType::Timetz(_) => crate::utils::parse_timetz(str), + CockroachType::Timestamptz(_) => super::utils::parse_timestamptz(str), + CockroachType::Timestamp(_) => super::utils::parse_timestamp(str), + CockroachType::Date => super::utils::parse_date(str), + CockroachType::Time(_) => super::utils::parse_time(str), + CockroachType::Timetz(_) => super::utils::parse_timetz(str), _ => unreachable!(), }, None => self.parse_json_datetime( diff --git a/psl/builtin-connectors/src/cockroach_datamodel_connector/native_types.rs b/psl/psl-core/src/builtin_connectors/cockroach_datamodel_connector/native_types.rs similarity index 100% rename from psl/builtin-connectors/src/cockroach_datamodel_connector/native_types.rs rename to psl/psl-core/src/builtin_connectors/cockroach_datamodel_connector/native_types.rs diff --git a/psl/builtin-connectors/src/cockroach_datamodel_connector/validations.rs b/psl/psl-core/src/builtin_connectors/cockroach_datamodel_connector/validations.rs similarity index 99% rename from psl/builtin-connectors/src/cockroach_datamodel_connector/validations.rs rename to psl/psl-core/src/builtin_connectors/cockroach_datamodel_connector/validations.rs index 72229184945b..fc504d4f15ff 100644 --- a/psl/builtin-connectors/src/cockroach_datamodel_connector/validations.rs +++ b/psl/psl-core/src/builtin_connectors/cockroach_datamodel_connector/validations.rs @@ -1,4 +1,4 @@ -use psl_core::{ +use crate::{ diagnostics::{DatamodelError, Diagnostics}, parser_database::{ walkers::{IndexWalker, ModelWalker}, diff --git a/psl/builtin-connectors/src/completions.rs b/psl/psl-core/src/builtin_connectors/completions.rs similarity index 96% rename from psl/builtin-connectors/src/completions.rs rename to psl/psl-core/src/builtin_connectors/completions.rs index a82db703910d..120bfae425f2 100644 --- a/psl/builtin-connectors/src/completions.rs +++ b/psl/psl-core/src/builtin_connectors/completions.rs @@ -1,7 +1,7 @@ +use crate::datamodel_connector::format_completion_docs; use lsp_types::{ CompletionItem, CompletionItemKind, CompletionList, Documentation, InsertTextFormat, MarkupContent, MarkupKind, }; -use psl_core::datamodel_connector::format_completion_docs; pub(crate) fn extensions_completion(completion_list: &mut CompletionList) { completion_list.items.push(CompletionItem { diff --git a/psl/builtin-connectors/src/lib.rs b/psl/psl-core/src/builtin_connectors/mod.rs similarity index 88% rename from psl/builtin-connectors/src/lib.rs rename to psl/psl-core/src/builtin_connectors/mod.rs index b99bbc4ef433..65ee251fad57 100644 --- a/psl/builtin-connectors/src/lib.rs +++ b/psl/psl-core/src/builtin_connectors/mod.rs @@ -1,6 +1,3 @@ -#![deny(rust_2018_idioms, unsafe_code)] -#![allow(clippy::derive_partial_eq_without_eq)] - pub mod cockroach_datamodel_connector; pub mod completions; @@ -18,7 +15,7 @@ mod postgres_datamodel_connector; mod sqlite_datamodel_connector; mod utils; -use psl_core::{datamodel_connector::Connector, ConnectorRegistry}; +use crate::{datamodel_connector::Connector, ConnectorRegistry}; pub const POSTGRES: &'static dyn Connector = &postgres_datamodel_connector::PostgresDatamodelConnector; pub const COCKROACH: &'static dyn Connector = &cockroach_datamodel_connector::CockroachDatamodelConnector; diff --git a/psl/builtin-connectors/src/mongodb.rs b/psl/psl-core/src/builtin_connectors/mongodb.rs similarity index 98% rename from psl/builtin-connectors/src/mongodb.rs rename to psl/psl-core/src/builtin_connectors/mongodb.rs index e2e820f6b166..e0f4615b985d 100644 --- a/psl/builtin-connectors/src/mongodb.rs +++ b/psl/psl-core/src/builtin_connectors/mongodb.rs @@ -3,9 +3,7 @@ mod validations; pub use mongodb_types::MongoDbType; -use enumflags2::BitFlags; -use mongodb_types::*; -use psl_core::{ +use crate::{ datamodel_connector::{ Connector, ConnectorCapabilities, ConnectorCapability, ConstraintScope, Flavour, NativeTypeConstructor, NativeTypeInstance, RelationMode, @@ -13,6 +11,8 @@ use psl_core::{ diagnostics::{Diagnostics, Span}, parser_database::{walkers::*, ReferentialAction, ScalarType}, }; +use enumflags2::BitFlags; +use mongodb_types::*; use std::result::Result as StdResult; const CAPABILITIES: ConnectorCapabilities = enumflags2::make_bitflags!(ConnectorCapability::{ @@ -82,7 +82,7 @@ impl Connector for MongoDbDatamodelConnector { fn validate_relation_field( &self, - field: psl_core::parser_database::walkers::RelationFieldWalker<'_>, + field: crate::parser_database::walkers::RelationFieldWalker<'_>, errors: &mut Diagnostics, ) { validations::relation_same_native_type(field, errors); diff --git a/psl/builtin-connectors/src/mongodb/mongodb_types.rs b/psl/psl-core/src/builtin_connectors/mongodb/mongodb_types.rs similarity index 97% rename from psl/builtin-connectors/src/mongodb/mongodb_types.rs rename to psl/psl-core/src/builtin_connectors/mongodb/mongodb_types.rs index c75a7f0b3bd4..501f0bc5f268 100644 --- a/psl/builtin-connectors/src/mongodb/mongodb_types.rs +++ b/psl/psl-core/src/builtin_connectors/mongodb/mongodb_types.rs @@ -1,5 +1,5 @@ +use crate::parser_database::ScalarType; use once_cell::sync::Lazy; -use psl_core::parser_database::ScalarType; use std::collections::HashMap; crate::native_type_definition! { diff --git a/psl/builtin-connectors/src/mongodb/validations.rs b/psl/psl-core/src/builtin_connectors/mongodb/validations.rs similarity index 99% rename from psl/builtin-connectors/src/mongodb/validations.rs rename to psl/psl-core/src/builtin_connectors/mongodb/validations.rs index d6abdf9a84e4..f3c5ce64cf2a 100644 --- a/psl/builtin-connectors/src/mongodb/validations.rs +++ b/psl/psl-core/src/builtin_connectors/mongodb/validations.rs @@ -1,4 +1,4 @@ -use psl_core::{ +use crate::{ diagnostics::{DatamodelError, DatamodelWarning, Diagnostics}, parser_database::{ ast::{WithName, WithSpan}, @@ -214,7 +214,7 @@ pub(crate) fn field_name_uses_valid_characters(field: ScalarFieldWalker<'_>, err /// Makes sure underlying fields of a relation have the same native types. pub(crate) fn relation_same_native_type( - field: psl_core::parser_database::walkers::RelationFieldWalker<'_>, + field: crate::parser_database::walkers::RelationFieldWalker<'_>, errors: &mut Diagnostics, ) { let references = field.referenced_fields(); diff --git a/psl/builtin-connectors/src/mssql_datamodel_connector.rs b/psl/psl-core/src/builtin_connectors/mssql_datamodel_connector.rs similarity index 98% rename from psl/builtin-connectors/src/mssql_datamodel_connector.rs rename to psl/psl-core/src/builtin_connectors/mssql_datamodel_connector.rs index 54e8b8eba006..1a3b9afac854 100644 --- a/psl/builtin-connectors/src/mssql_datamodel_connector.rs +++ b/psl/psl-core/src/builtin_connectors/mssql_datamodel_connector.rs @@ -3,9 +3,7 @@ mod validations; pub use native_types::{MsSqlType, MsSqlTypeParameter}; -use enumflags2::BitFlags; -use lsp_types::{CompletionItem, CompletionItemKind, CompletionList}; -use psl_core::{ +use crate::{ datamodel_connector::{ Connector, ConnectorCapabilities, ConnectorCapability, ConstraintScope, Flavour, NativeTypeConstructor, NativeTypeInstance, RelationMode, @@ -14,11 +12,13 @@ use psl_core::{ parser_database::{self, ast, ParserDatabase, ReferentialAction, ScalarType}, PreviewFeature, }; +use enumflags2::BitFlags; +use lsp_types::{CompletionItem, CompletionItemKind, CompletionList}; use MsSqlType::*; use MsSqlTypeParameter::*; -use crate::completions; +use super::completions; const CONSTRAINT_SCOPES: &[ConstraintScope] = &[ ConstraintScope::GlobalPrimaryKeyForeignKeyDefault, @@ -269,7 +269,7 @@ impl Connector for MsSqlDatamodelConnector { } } - fn datasource_completions(&self, config: &psl_core::Configuration, completion_list: &mut CompletionList) { + fn datasource_completions(&self, config: &crate::Configuration, completion_list: &mut CompletionList) { let ds = match config.datasources.first() { Some(ds) => ds, None => return, diff --git a/psl/builtin-connectors/src/mssql_datamodel_connector/native_types.rs b/psl/psl-core/src/builtin_connectors/mssql_datamodel_connector/native_types.rs similarity index 97% rename from psl/builtin-connectors/src/mssql_datamodel_connector/native_types.rs rename to psl/psl-core/src/builtin_connectors/mssql_datamodel_connector/native_types.rs index 06898c2ee08a..5ef24a40464d 100644 --- a/psl/builtin-connectors/src/mssql_datamodel_connector/native_types.rs +++ b/psl/psl-core/src/builtin_connectors/mssql_datamodel_connector/native_types.rs @@ -6,7 +6,7 @@ pub enum MsSqlTypeParameter { Max, } -impl psl_core::datamodel_connector::NativeTypeArguments for MsSqlTypeParameter { +impl crate::datamodel_connector::NativeTypeArguments for MsSqlTypeParameter { const DESCRIPTION: &'static str = "an integer or `Max`"; const OPTIONAL_ARGUMENTS_COUNT: usize = 0; const REQUIRED_ARGUMENTS_COUNT: usize = 1; diff --git a/psl/builtin-connectors/src/mssql_datamodel_connector/validations.rs b/psl/psl-core/src/builtin_connectors/mssql_datamodel_connector/validations.rs similarity index 99% rename from psl/builtin-connectors/src/mssql_datamodel_connector/validations.rs rename to psl/psl-core/src/builtin_connectors/mssql_datamodel_connector/validations.rs index 5ff142b24273..345eb3d9de7a 100644 --- a/psl/builtin-connectors/src/mssql_datamodel_connector/validations.rs +++ b/psl/psl-core/src/builtin_connectors/mssql_datamodel_connector/validations.rs @@ -1,5 +1,5 @@ use super::MsSqlType; -use psl_core::{ +use crate::{ datamodel_connector::{walker_ext_traits::ScalarFieldWalkerExt, Connector}, diagnostics::{DatamodelError, Diagnostics}, parser_database::{ diff --git a/psl/builtin-connectors/src/mysql_datamodel_connector.rs b/psl/psl-core/src/builtin_connectors/mysql_datamodel_connector.rs similarity index 98% rename from psl/builtin-connectors/src/mysql_datamodel_connector.rs rename to psl/psl-core/src/builtin_connectors/mysql_datamodel_connector.rs index 39995fb5d48d..c48c3ec940e1 100644 --- a/psl/builtin-connectors/src/mysql_datamodel_connector.rs +++ b/psl/psl-core/src/builtin_connectors/mysql_datamodel_connector.rs @@ -3,10 +3,8 @@ mod validations; pub use native_types::MySqlType; -use crate::completions; -use enumflags2::BitFlags; -use lsp_types::CompletionList; -use psl_core::{ +use super::completions; +use crate::{ datamodel_connector::{ Connector, ConnectorCapabilities, ConnectorCapability, ConstraintScope, Flavour, NativeTypeConstructor, NativeTypeInstance, RelationMode, @@ -15,6 +13,8 @@ use psl_core::{ parser_database::{walkers, ReferentialAction, ScalarType}, PreviewFeature, }; +use enumflags2::BitFlags; +use lsp_types::CompletionList; use MySqlType::*; const TINY_BLOB_TYPE_NAME: &str = "TinyBlob"; @@ -270,7 +270,7 @@ impl Connector for MySqlDatamodelConnector { Ok(()) } - fn datasource_completions(&self, config: &psl_core::Configuration, completion_list: &mut CompletionList) { + fn datasource_completions(&self, config: &crate::Configuration, completion_list: &mut CompletionList) { let ds = match config.datasources.first() { Some(ds) => ds, None => return, diff --git a/psl/builtin-connectors/src/mysql_datamodel_connector/native_types.rs b/psl/psl-core/src/builtin_connectors/mysql_datamodel_connector/native_types.rs similarity index 100% rename from psl/builtin-connectors/src/mysql_datamodel_connector/native_types.rs rename to psl/psl-core/src/builtin_connectors/mysql_datamodel_connector/native_types.rs diff --git a/psl/builtin-connectors/src/mysql_datamodel_connector/validations.rs b/psl/psl-core/src/builtin_connectors/mysql_datamodel_connector/validations.rs similarity index 94% rename from psl/builtin-connectors/src/mysql_datamodel_connector/validations.rs rename to psl/psl-core/src/builtin_connectors/mysql_datamodel_connector/validations.rs index e96ab4ab4078..e63351335830 100644 --- a/psl/builtin-connectors/src/mysql_datamodel_connector/validations.rs +++ b/psl/psl-core/src/builtin_connectors/mysql_datamodel_connector/validations.rs @@ -1,12 +1,14 @@ -use indoc::formatdoc; -use psl_core::diagnostics::{DatamodelWarning, Span}; -use psl_core::parser_database::ast::WithSpan; -use psl_core::parser_database::ReferentialAction; -use psl_core::{ +use crate::{ datamodel_connector::{walker_ext_traits::ScalarFieldWalkerExt, Connector}, diagnostics::Diagnostics, - parser_database::walkers::{IndexWalker, PrimaryKeyWalker, RelationFieldWalker}, + diagnostics::{DatamodelWarning, Span}, + parser_database::{ + ast::WithSpan, + walkers::{IndexWalker, PrimaryKeyWalker, RelationFieldWalker}, + ReferentialAction, + }, }; +use indoc::formatdoc; const LENGTH_GUIDE: &str = " Please use the `length` argument to the field in the index definition to allow this."; diff --git a/psl/builtin-connectors/src/native_type_definition.rs b/psl/psl-core/src/builtin_connectors/native_type_definition.rs similarity index 85% rename from psl/builtin-connectors/src/native_type_definition.rs rename to psl/psl-core/src/builtin_connectors/native_type_definition.rs index b066961b3226..c4e5d1df2007 100644 --- a/psl/builtin-connectors/src/native_type_definition.rs +++ b/psl/psl-core/src/builtin_connectors/native_type_definition.rs @@ -52,8 +52,8 @@ macro_rules! native_type_definition { pub fn from_parts( name: &str, arguments: &[String], - span: psl_core::parser_database::ast::Span, - diagnostics: &mut psl_core::diagnostics::Diagnostics + span: $crate::parser_database::ast::Span, + diagnostics: &mut $crate::diagnostics::Diagnostics ) -> Option { use $enumName::*; @@ -130,7 +130,7 @@ macro_rules! native_type_definition { $self, { $($body)* - $variant(arg) => (stringify!($variant), <$param as psl_core::datamodel_connector::NativeTypeArguments>::to_parts(arg)), + $variant(arg) => (stringify!($variant), <$param as $crate::datamodel_connector::NativeTypeArguments>::to_parts(arg)), } $($tail)* } @@ -163,7 +163,7 @@ macro_rules! native_type_definition { match $name { $($body)* _ => { - $diagnostics.push_error(psl_core::diagnostics::DatamodelError::new_native_type_parser_error($name, $span)); + $diagnostics.push_error($crate::diagnostics::DatamodelError::new_native_type_parser_error($name, $span)); None }, } @@ -182,12 +182,12 @@ macro_rules! native_type_definition { { $($body)* name if name == stringify!($variant) => { - let args = <$params as psl_core::datamodel_connector::NativeTypeArguments>::from_parts($arguments); + let args = <$params as $crate::datamodel_connector::NativeTypeArguments>::from_parts($arguments); match args { Some(args) => Some($variant(args)), None => { let rendered_args = format!("({})", $arguments.join(", ")); - $diagnostics.push_error(psl_core::diagnostics::DatamodelError::new_value_parser_error(<$params as psl_core::datamodel_connector::NativeTypeArguments>::DESCRIPTION, &rendered_args, $span)); + $diagnostics.push_error($crate::diagnostics::DatamodelError::new_value_parser_error(<$params as $crate::datamodel_connector::NativeTypeArguments>::DESCRIPTION, &rendered_args, $span)); None } } @@ -221,7 +221,7 @@ macro_rules! native_type_definition { { $($body:tt)* } ) => { #[allow(unused_imports)] - use psl_core::datamodel_connector::NativeTypeConstructor; + use $crate::datamodel_connector::NativeTypeConstructor; pub(crate) const CONSTRUCTORS: &[NativeTypeConstructor] = &[ $( $body )* @@ -242,7 +242,7 @@ macro_rules! native_type_definition { name: stringify!($variant), number_of_args: 0, number_of_optional_args: 0, - prisma_types: &[$(psl_core::parser_database::ScalarType::$scalar),*], + prisma_types: &[$($crate::parser_database::ScalarType::$scalar),*], }, } $($tail)* @@ -261,9 +261,9 @@ macro_rules! native_type_definition { $($body)* NativeTypeConstructor { name: stringify!($variant), - number_of_args: <$params as psl_core::datamodel_connector::NativeTypeArguments>::REQUIRED_ARGUMENTS_COUNT, - number_of_optional_args: <$params as psl_core::datamodel_connector::NativeTypeArguments>::OPTIONAL_ARGUMENTS_COUNT, - prisma_types: &[$(psl_core::parser_database::ScalarType::$scalar),*], + number_of_args: <$params as $crate::datamodel_connector::NativeTypeArguments>::REQUIRED_ARGUMENTS_COUNT, + number_of_optional_args: <$params as $crate::datamodel_connector::NativeTypeArguments>::OPTIONAL_ARGUMENTS_COUNT, + prisma_types: &[$($crate::parser_database::ScalarType::$scalar),*], }, } $($tail)* diff --git a/psl/builtin-connectors/src/postgres_datamodel_connector.rs b/psl/psl-core/src/builtin_connectors/postgres_datamodel_connector.rs similarity index 98% rename from psl/builtin-connectors/src/postgres_datamodel_connector.rs rename to psl/psl-core/src/builtin_connectors/postgres_datamodel_connector.rs index fa3325d1403f..98bb4e723dfb 100644 --- a/psl/builtin-connectors/src/postgres_datamodel_connector.rs +++ b/psl/psl-core/src/builtin_connectors/postgres_datamodel_connector.rs @@ -4,10 +4,7 @@ mod validations; pub use native_types::PostgresType; -use chrono::*; -use enumflags2::BitFlags; -use lsp_types::{CompletionItem, CompletionItemKind, CompletionList, InsertTextFormat}; -use psl_core::{ +use crate::{ datamodel_connector::{ Connector, ConnectorCapabilities, ConnectorCapability, ConstraintScope, Flavour, NativeTypeConstructor, NativeTypeInstance, RelationMode, StringFilter, @@ -16,10 +13,13 @@ use psl_core::{ parser_database::{ast, walkers, IndexAlgorithm, OperatorClass, ParserDatabase, ReferentialAction, ScalarType}, Configuration, Datasource, DatasourceConnectorData, PreviewFeature, }; +use chrono::*; +use enumflags2::BitFlags; +use lsp_types::{CompletionItem, CompletionItemKind, CompletionList, InsertTextFormat}; use std::{borrow::Cow, collections::HashMap}; use PostgresType::*; -use crate::completions; +use super::completions; const CONSTRAINT_SCOPES: &[ConstraintScope] = &[ ConstraintScope::GlobalPrimaryKeyKeyIndex, @@ -578,11 +578,11 @@ impl Connector for PostgresDatamodelConnector { match native_type { Some(pt) => match pt { - Timestamptz(_) => crate::utils::parse_timestamptz(str), - Timestamp(_) => crate::utils::parse_timestamp(str), - Date => crate::utils::parse_date(str), - Time(_) => crate::utils::parse_time(str), - Timetz(_) => crate::utils::parse_timetz(str), + Timestamptz(_) => super::utils::parse_timestamptz(str), + Timestamp(_) => super::utils::parse_timestamp(str), + Date => super::utils::parse_date(str), + Time(_) => super::utils::parse_time(str), + Timetz(_) => super::utils::parse_timetz(str), _ => unreachable!(), }, None => self.parse_json_datetime( diff --git a/psl/builtin-connectors/src/postgres_datamodel_connector/datasource.rs b/psl/psl-core/src/builtin_connectors/postgres_datamodel_connector/datasource.rs similarity index 96% rename from psl/builtin-connectors/src/postgres_datamodel_connector/datasource.rs rename to psl/psl-core/src/builtin_connectors/postgres_datamodel_connector/datasource.rs index e394f8bc86bd..b208548d5d6c 100644 --- a/psl/builtin-connectors/src/postgres_datamodel_connector/datasource.rs +++ b/psl/psl-core/src/builtin_connectors/postgres_datamodel_connector/datasource.rs @@ -1,6 +1,5 @@ -use super::PostgresExtensions; -use crate::postgres_datamodel_connector::PostgresExtension; -use psl_core::{ +use super::{PostgresExtension, PostgresExtensions}; +use crate::{ datamodel_connector::EXTENSIONS_KEY, diagnostics::{DatamodelError, Diagnostics}, parser_database::{ast, coerce, coerce_array}, diff --git a/psl/builtin-connectors/src/postgres_datamodel_connector/native_types.rs b/psl/psl-core/src/builtin_connectors/postgres_datamodel_connector/native_types.rs similarity index 100% rename from psl/builtin-connectors/src/postgres_datamodel_connector/native_types.rs rename to psl/psl-core/src/builtin_connectors/postgres_datamodel_connector/native_types.rs diff --git a/psl/builtin-connectors/src/postgres_datamodel_connector/validations.rs b/psl/psl-core/src/builtin_connectors/postgres_datamodel_connector/validations.rs similarity index 99% rename from psl/builtin-connectors/src/postgres_datamodel_connector/validations.rs rename to psl/psl-core/src/builtin_connectors/postgres_datamodel_connector/validations.rs index c46a3dd7264b..d6acef241311 100644 --- a/psl/builtin-connectors/src/postgres_datamodel_connector/validations.rs +++ b/psl/psl-core/src/builtin_connectors/postgres_datamodel_connector/validations.rs @@ -1,11 +1,11 @@ -use crate::PostgresType; -use enumflags2::BitFlags; -use psl_core::{ +use super::PostgresType; +use crate::{ datamodel_connector::{walker_ext_traits::*, Connector}, diagnostics::{DatamodelError, Diagnostics}, parser_database::{ast::WithSpan, walkers::IndexWalker, IndexAlgorithm, OperatorClass}, PreviewFeature, }; +use enumflags2::BitFlags; use super::PostgresDatasourceProperties; diff --git a/psl/builtin-connectors/src/sqlite_datamodel_connector.rs b/psl/psl-core/src/builtin_connectors/sqlite_datamodel_connector.rs similarity index 99% rename from psl/builtin-connectors/src/sqlite_datamodel_connector.rs rename to psl/psl-core/src/builtin_connectors/sqlite_datamodel_connector.rs index 76c90bc97c96..78da6eeff61e 100644 --- a/psl/builtin-connectors/src/sqlite_datamodel_connector.rs +++ b/psl/psl-core/src/builtin_connectors/sqlite_datamodel_connector.rs @@ -1,5 +1,4 @@ -use enumflags2::BitFlags; -use psl_core::{ +use crate::{ datamodel_connector::{ Connector, ConnectorCapabilities, ConnectorCapability, ConstraintScope, Flavour, NativeTypeConstructor, NativeTypeInstance, @@ -7,6 +6,7 @@ use psl_core::{ diagnostics::{DatamodelError, Diagnostics, Span}, parser_database::{ReferentialAction, ScalarType}, }; +use enumflags2::BitFlags; const NATIVE_TYPE_CONSTRUCTORS: &[NativeTypeConstructor] = &[]; const CONSTRAINT_SCOPES: &[ConstraintScope] = &[ConstraintScope::GlobalKeyIndex]; diff --git a/psl/builtin-connectors/src/utils.rs b/psl/psl-core/src/builtin_connectors/utils.rs similarity index 100% rename from psl/builtin-connectors/src/utils.rs rename to psl/psl-core/src/builtin_connectors/utils.rs diff --git a/psl/psl-core/src/lib.rs b/psl/psl-core/src/lib.rs index 2bcd70190398..ca0ce37cc0f1 100644 --- a/psl/psl-core/src/lib.rs +++ b/psl/psl-core/src/lib.rs @@ -2,6 +2,7 @@ #![deny(rust_2018_idioms, unsafe_code)] #![allow(clippy::derive_partial_eq_without_eq)] +pub mod builtin_connectors; pub mod datamodel_connector; /// `mcf`: Turns a collection of `configuration::Datasource` and `configuration::Generator` into a diff --git a/psl/psl/Cargo.toml b/psl/psl/Cargo.toml index ef5ee0939a85..148a4c3da5e7 100644 --- a/psl/psl/Cargo.toml +++ b/psl/psl/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" edition = "2021" [dependencies] -builtin-psl-connectors = { path = "../builtin-connectors" } psl-core = { path = "../psl-core" } [dev-dependencies] diff --git a/psl/psl/src/lib.rs b/psl/psl/src/lib.rs index 215d962aa447..a00400125c69 100644 --- a/psl/psl/src/lib.rs +++ b/psl/psl/src/lib.rs @@ -1,7 +1,7 @@ #![doc = include_str!("../README.md")] #![deny(rust_2018_idioms, unsafe_code, missing_docs)] -pub use builtin_psl_connectors as builtin_connectors; +pub use psl_core::builtin_connectors; pub use psl_core::{ datamodel_connector, diagnostics::{self, Diagnostics}, diff --git a/psl/psl/tests/config/datasources.rs b/psl/psl/tests/config/datasources.rs index 9ce2c3ea7db3..fda520e3f576 100644 --- a/psl/psl/tests/config/datasources.rs +++ b/psl/psl/tests/config/datasources.rs @@ -1,4 +1,4 @@ -use builtin_psl_connectors::PostgresDatasourceProperties; +use psl::builtin_connectors::PostgresDatasourceProperties; use crate::common::*;