Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spacedrive changes #454

Merged
merged 23 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,970 changes: 1,274 additions & 696 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ members = [
"tests/*/*",
"crates/*",
"crates/sdk/example/*",
"prisma-cli"
"prisma-cli",
]
exclude = ["examples/tauri"]
resolver = "2"
Expand All @@ -27,7 +27,11 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

convert_case = "0.6.0"
rspc = { version = "=1.0.0-rc.5" }

specta = { version = "=2.0.0-rc.1" }
tauri-specta = { git = "https://github.com/oscartbeaumont/tauri-specta", branch = "v2" }
tauri-specta = { version = "2.0.0-rc.9" }

# This is a deprecated feature so we don't really care about the verison
rspc = "*"

# We don't lock version cause PCR only depends on `derive(Type)` so it should be fine.
specta = "^2.0.0-rc"
5 changes: 4 additions & 1 deletion crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ proc-macro2 = "1.0.39"
http = "0.2.6"
directories = "4.0.1"
flate2 = "1.0.23"
reqwest = { version = "0.11.10", features = ["blocking"] }
reqwest = { version = "0.11.10", features = [
"blocking",
"native-tls-vendored",
] }
regex = "1.5.5"
thiserror = "1.0.37"

Expand Down
5 changes: 3 additions & 2 deletions crates/generator-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ edition = "2021"
[lib]
proc-macro = true

[features]
specta = []

[dependencies]
prisma-client-rust-generator-shared = { path = "../generator-shared" }
convert_case.workspace = true
proc-macro2 = "1.0.39"
quote = "1.0.18"
syn = "1.0.91"

specta = { workspace = true, optional = true }
2 changes: 1 addition & 1 deletion crates/generator-macros/src/partial_unchecked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub fn proc_macro(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let specta_attrs = cfg!(feature = "specta").then(|| {
quote! {
#[derive(::prisma_client_rust::specta::Type)]
#[specta(crate = "prisma_client_rust::specta")]
#[specta(crate = prisma_client_rust::specta)]
}
});

Expand Down
15 changes: 8 additions & 7 deletions crates/generator-macros/src/select_include/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub fn definitions(input: &Input) -> TokenStream {
if cfg!(feature = "specta") {
attrs.extend(quote! {
#[derive(::prisma_client_rust::specta::Type)]
#[specta(crate = "prisma_client_rust::specta")]
#[specta(crate = prisma_client_rust::specta)]
});

attrs.extend(match &macro_rules.name {
Expand Down Expand Up @@ -62,9 +62,10 @@ pub fn definitions(input: &Input) -> TokenStream {
let (field_type, field_module) = field_in_selectables
.zip(field_in_selection.and_then(|f| f.sub_selection.as_ref()))
.and_then(|(field_in_selectables, (variant, sub_selection))| {
let Arity::Relation(relation_model_path, arity) = &field_in_selectables.arity else {
return None;
};
let Arity::Relation(relation_model_path, arity) = &field_in_selectables.arity
else {
return None;
};

let value = quote! {
pub mod #ident {
Expand All @@ -77,9 +78,9 @@ pub fn definitions(input: &Input) -> TokenStream {
let base = quote!(#ident::Data);

let typ = match arity {
RelationArity::One => base,
RelationArity::Many => quote!(Vec<#base>),
RelationArity::Optional => quote!(Option<#base>),
RelationArity::One => base,
RelationArity::Many => quote!(Vec<#base>),
RelationArity::Optional => quote!(Option<#base>),
};

Some((typ, Some(value)))
Expand Down
5 changes: 4 additions & 1 deletion crates/generator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ proc-macro2 = "1.0.39"
http = "0.2.6"
directories = "4.0.1"
flate2 = "1.0.23"
reqwest = { version = "0.11.10", features = ["blocking"] }
reqwest = { version = "0.11.10", features = [
"blocking",
"native-tls-vendored",
] }
regex = "1.5.5"
thiserror = "1.0.37"

Expand Down
2 changes: 1 addition & 1 deletion crates/generator/src/composite_types/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn struct_definition(ty: CompositeTypeWalker) -> TokenStream {

quote! {
#[derive(::prisma_client_rust::specta::Type)]
#[specta(rename = #ty_name_pascal_str, crate = "prisma_client_rust::specta")]
#[specta(rename = #ty_name_pascal_str, crate = prisma_client_rust::specta)]
}
});

Expand Down
2 changes: 1 addition & 1 deletion crates/generator/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn generate(args: &GenerateArgs) -> TokenStream {

quote! {
#[derive(::prisma_client_rust::specta::Type)]
#[specta(rename = #model_name_pascal_str, crate = "prisma_client_rust::specta")]
#[specta(rename = #model_name_pascal_str, crate = prisma_client_rust::specta)]
}
});

Expand Down
2 changes: 1 addition & 1 deletion crates/generator/src/models/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ pub fn r#struct(model: ModelWalker) -> TokenStream {

quote! {
#[derive(::prisma_client_rust::specta::Type)]
#[specta(rename = #model_name_pascal_str, crate = "prisma_client_rust::specta")]
#[specta(rename = #model_name_pascal_str, crate = prisma_client_rust::specta)]
}
});

Expand Down
11 changes: 9 additions & 2 deletions crates/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ default = []
rspc = ["dep:rspc", "specta"]
specta = ["dep:specta", "prisma-client-rust-generator-macros/specta"]
sqlite-create-many = ["psl/sqlite-create-many"]
migrations = ["schema-core", "dep:include_dir", "dep:tempfile", "tokio/fs", "dep:tracing"]
migrations = [
"schema-core",
"dep:include_dir",
"dep:tempfile",
"tokio/fs",
"dep:tracing",
]
mocking = ["tokio"]
# mutation-callbacks = []

Expand All @@ -27,7 +33,8 @@ serde.workspace = true
serde_json.workspace = true
chrono = { version = "0.4.19", features = ["serde"] }
thiserror = "1.0.30"
bigdecimal = { version = "0.3", features = ["serde"] }
bigdecimal = { version = "0.4", features = ["serde"] }
bigdecimal_03 = { package = "bigdecimal", version = "0.3" }
uuid = { version = "1", features = ["serde"] }
indexmap = "1.8.2"
serde-value = "0.7.0"
Expand Down
3 changes: 2 additions & 1 deletion crates/lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ use std::collections::HashMap;

pub use bigdecimal;
pub use chrono;
pub use prisma_models::{self, PrismaValue};
pub use prisma_models;
pub use prisma_value::PrismaValue;
pub use psl;
pub use query_core;
pub use query_core::{schema, Selection};
Expand Down
29 changes: 17 additions & 12 deletions crates/lib/src/prisma_value.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::{str::FromStr, sync::Arc};

use bigdecimal::{BigDecimal, FromPrimitive, ToPrimitive};
use chrono::{DateTime, FixedOffset};
use indexmap::IndexMap;
use query_core::{
constants::custom_types::{self},
Expand All @@ -10,6 +9,8 @@ use query_core::{
use serde::{Serialize, Serializer};
use uuid::Uuid;

use crate::scalar_types;

/// A Rust-friendly version of Prisma's own PrismaValue.
///
/// Prisma's PrismaValue has serialization overrides that make it suitable for JSON serialization,
Expand All @@ -20,22 +21,22 @@ use uuid::Uuid;
#[derive(Debug, Clone, Serialize)]
#[serde(untagged)]
pub enum PrismaValue {
String(String),
Boolean(bool),
String(scalar_types::String),
Boolean(scalar_types::Boolean),
Enum(String),
Int(i32),
Int(scalar_types::Int),
Uuid(Uuid),
List(Vec<PrismaValue>),
Json(serde_json::Value),
Json(scalar_types::Json),
Object(Vec<(String, PrismaValue)>),
#[serde(serialize_with = "serialize_null")]
Null,
DateTime(DateTime<FixedOffset>),
Float(f64),
DateTime(scalar_types::DateTime),
Float(scalar_types::Float),
// Special variant for distinguishing between Float and Decimal
Decimal(BigDecimal),
BigInt(i64),
Bytes(Vec<u8>),
Decimal(scalar_types::Decimal),
BigInt(scalar_types::BigInt),
Bytes(scalar_types::Bytes),
}

/// A Rust-friendly version of Prisma's own Item.
Expand Down Expand Up @@ -145,8 +146,12 @@ impl From<PrismaValue> for prisma_models::PrismaValue {
}
PrismaValue::Null => Self::Null,
PrismaValue::DateTime(value) => Self::DateTime(value),
PrismaValue::Decimal(value) => Self::Float(value),
PrismaValue::Float(value) => Self::Float(BigDecimal::from_f64(value).unwrap()),
PrismaValue::Decimal(value) => {
Self::Float(bigdecimal_03::BigDecimal::from_str(&value.to_string()).unwrap())
}
PrismaValue::Float(value) => {
Self::Float(bigdecimal_03::BigDecimal::from_f64(value).unwrap())
}
PrismaValue::BigInt(value) => Self::BigInt(value),
PrismaValue::Bytes(value) => Self::Bytes(value),
}
Expand Down
10 changes: 4 additions & 6 deletions crates/lib/src/queries/count.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use prisma_models::PrismaValue;
use query_core::{Operation, Selection};
use serde::Deserialize;

use crate::{
merge_fields, ModelOperation, ModelQuery, ModelReadOperation, ModelTypes, OrderByQuery,
PaginatedQuery, PrismaClientInternals, Query, QueryConvert, SerializedWhereInput, WhereInput,
PaginatedQuery, PrismaClientInternals, PrismaValue, Query, QueryConvert, WhereInput,
WhereQuery,
};

Expand Down Expand Up @@ -112,14 +111,13 @@ impl<'a, Actions: ModelTypes> Query<'a> for Count<'a, Actions> {
.map(WhereInput::serialize)
.map(|s| (s.field, s.value.into()))
.collect(),
)
.into(),
),
)
}),
self.skip
.map(|skip| ("skip".to_string(), PrismaValue::Int(skip as i64).into())),
.map(|skip| ("skip".to_string(), PrismaValue::Int(skip as i32))),
self.take
.map(|take| ("take".to_string(), PrismaValue::Int(take as i64).into())),
.map(|take| ("take".to_string(), PrismaValue::Int(take as i32))),
]
.into_iter()
.flatten(),
Expand Down
8 changes: 3 additions & 5 deletions crates/lib/src/queries/create.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use prisma_models::PrismaValue;
use query_core::{Operation, Selection};

use crate::{
merge_fields, Include, IncludeType, ModelOperation, ModelQuery, ModelTypes,
ModelWriteOperation, PrismaClientInternals, Query, QueryConvert, Select, SelectType, SetQuery,
WithQuery,
ModelWriteOperation, PrismaClientInternals, PrismaValue, Query, QueryConvert, Select,
SelectType, SetQuery, WithQuery,
};

pub struct Create<'a, Actions: ModelTypes> {
Expand Down Expand Up @@ -36,8 +35,7 @@ impl<'a, Actions: ModelTypes> Create<'a, Actions> {
"data".to_string(),
PrismaValue::Object(merge_fields(
set_params.into_iter().map(Into::into).collect(),
))
.into(),
)),
)]
.into_iter(),
nested_selections,
Expand Down
6 changes: 2 additions & 4 deletions crates/lib/src/queries/create_many.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use prisma_models::PrismaValue;
use query_core::{Operation, Selection};

use crate::{
merge_fields, BatchResult, ModelOperation, ModelQuery, ModelTypes, ModelWriteOperation,
PrismaClientInternals, Query, QueryConvert,
PrismaClientInternals, PrismaValue, Query, QueryConvert,
};

pub struct CreateMany<'a, Actions: ModelTypes> {
Expand Down Expand Up @@ -48,8 +47,7 @@ impl<'a, Actions: ModelTypes> CreateMany<'a, Actions> {
))
})
.collect(),
)
.into(),
),
)),
_skip_duplicates.then(|| {
(
Expand Down
8 changes: 3 additions & 5 deletions crates/lib/src/queries/create_unchecked.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use prisma_models::PrismaValue;
use query_core::{Operation, Selection};

use crate::{
merge_fields, Include, IncludeType, ModelOperation, ModelQuery, ModelTypes,
ModelWriteOperation, PrismaClientInternals, Query, QueryConvert, Select, SelectType,
UncheckedSetQuery, WithQuery,
ModelWriteOperation, PrismaClientInternals, PrismaValue, Query, QueryConvert, Select,
SelectType, UncheckedSetQuery, WithQuery,
};

pub struct CreateUnchecked<'a, Actions: ModelTypes> {
Expand Down Expand Up @@ -36,8 +35,7 @@ impl<'a, Actions: ModelTypes> CreateUnchecked<'a, Actions> {
"data".to_string(),
PrismaValue::Object(merge_fields(
set_params.into_iter().map(Into::into).collect(),
))
.into(),
)),
)]
.into_iter(),
nested_selections,
Expand Down
6 changes: 3 additions & 3 deletions crates/lib/src/queries/delete.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use prisma_models::PrismaValue;
use query_core::{Operation, Selection};

use crate::{
Include, IncludeType, ModelOperation, ModelQuery, ModelTypes, ModelWriteOperation,
PrismaClientInternals, Query, QueryConvert, Select, SelectType, WhereInput, WithQuery,
PrismaClientInternals, PrismaValue, Query, QueryConvert, Select, SelectType, WhereInput,
WithQuery,
};

pub struct Delete<'a, Actions: ModelTypes> {
Expand Down Expand Up @@ -37,7 +37,7 @@ impl<'a, Actions: ModelTypes> Delete<'a, Actions> {
Self::base_selection(
[(
"where".to_string(),
PrismaValue::Object(vec![where_param.serialize().transform_equals()]).into(),
PrismaValue::Object(vec![where_param.serialize().transform_equals()]),
)],
nested_selections,
)
Expand Down
6 changes: 2 additions & 4 deletions crates/lib/src/queries/delete_many.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ use query_core::Operation;

use crate::{
merge_fields, BatchResult, ModelOperation, ModelQuery, ModelTypes, ModelWriteOperation,
PrismaClientInternals, Query, QueryConvert, WhereInput, WhereQuery,
PrismaClientInternals, PrismaValue, Query, QueryConvert, WhereInput, WhereQuery,
};
use prisma_models::PrismaValue;

pub struct DeleteMany<'a, Actions: ModelTypes> {
client: &'a PrismaClientInternals,
Expand Down Expand Up @@ -50,8 +49,7 @@ impl<'a, Actions: ModelTypes> Query<'a> for DeleteMany<'a, Actions> {
.map(WhereInput::serialize)
.map(|s| (s.field, s.value.into()))
.collect(),
))
.into(),
)),
)
})]
.into_iter()
Expand Down
Loading
Loading