Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
oscartbeaumont committed Sep 21, 2023
1 parent 3ea7502 commit 5d0347a
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 42 deletions.
6 changes: 3 additions & 3 deletions macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ documentation = "https://docs.rs/specta/latest/specta"
keywords = ["async", "specta", "rspc", "typescript", "typesafe"]
categories = ["web-programming", "asynchronous"]

[lib]
proc-macro = true

[features]
serde = []
functions = []
export = []

[lib]
proc-macro = true

[dependencies]
Inflector = { version = "0.11.4", default-features = false }
itertools = "0.10.5"
Expand Down
8 changes: 8 additions & 0 deletions src/datatype/enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ pub enum EnumRepr {
},
}

// TODO: Refactor into this instead
// pub struct EnumVariant {
// name: Cow<'static, str>,
// deprecated: Option<DeprecatedTy>,
// comments: Vec<Cow<'static, str>>,
// variant: EnumVariantTy,
// }

/// Type of an [`EnumType`] variant.
#[derive(Debug, Clone, PartialEq)]
pub enum EnumVariant {
Expand Down
22 changes: 22 additions & 0 deletions src/datatype/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,28 @@ impl DataTypeReference {
}
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum DeprecatedType {
/// A type that has been deprecated without a message.
///
/// Eg. `#[deprecated]`
Deprecated,
/// A type that has been deprecated with a message.
///
/// Eg. `#[deprecated = "Use something else"]`
#[non_exhaustive]
DeprecatedWithMsg { message: Cow<'static, str> },
/// A type that has been deprecated with a message and a `since` version.
///
/// Eg. `#[deprecated(since = "1.0.0", message = "Use something else")]`
#[non_exhaustive]
DeprecatedWithSince {
since: Option<Cow<'static, str>>,
message: Option<Cow<'static, str>>,
},
}

/// A generic ("placeholder") argument to a Specta-enabled type.
///
/// A generic does not hold a specific type instead it acts as a slot where a type can be provided when referencing this type.
Expand Down
50 changes: 50 additions & 0 deletions tests/deprecated.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#[allow(deprecated)]
#[derive(Type)]
#[specta(export = false)]
#[deprecated]
struct DeprecatedType {
a: i32,
}

#[derive(Type)]
#[specta(export = false)]
#[deprecated = "Look at you big man using a deprecation message"]
struct DeprecatedTypeWithMsg {
a: i32,
}

#[derive(Type)]
#[specta(export = false)]
#[deprecated(note = "Look at you big man using a deprecation message")]
struct DeprecatedTypeWithMsg2 {
a: i32,
}

#[derive(Type)]
#[specta(export = false)]
struct DeprecatedFields {
a: i32,
#[deprecated]
b: String,
#[deprecated = "This field is cringe!"]
c: String,
#[deprecated(note = "This field is cringe!")]
d: String,
}

#[derive(Type)]
#[specta(export = false)]
pub struct DeprecatedTupleVariant(
#[deprecated] String,
#[deprecated = "Nope"] String,
#[deprecated(note = "Nope")] i32,
);

#[test]
fn test_deprecated_types() {
assert_ts_export!(DeprecatedType, "");
assert_ts_export!(DeprecatedTypeWithMsg, "");
assert_ts_export!(DeprecatedTypeWithMsg2, "");
assert_ts_export!(DeprecatedFields, "");
assert_ts_export!(DeprecatedTupleVariant, "");
}
39 changes: 0 additions & 39 deletions tests/ts.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![allow(deprecated)]

use std::{
cell::RefCell,
collections::HashMap,
Expand Down Expand Up @@ -249,10 +247,6 @@ fn typescript_types() {
MyEmptyInput,
"export type MyEmptyInput = Record<string, never>"
);

// assert_ts_export!(DeprecatedType, "");
// assert_ts_export!(DeprecatedTypeWithMsg, "");
// assert_ts_export!(DeprecatedFields, "");
}

#[derive(Type)]
Expand Down Expand Up @@ -537,36 +531,3 @@ pub struct EnumReferenceRecordKey {
#[serde(rename_all = "camelCase")]
#[serde(default)]
pub(super) struct MyEmptyInput {}

// #[derive(Type)]
// #[specta(export = false)]
// #[deprecated]
// struct DeprecatedType {
// a: i32,
// }

// #[derive(Type)]
// #[specta(export = false)]
// #[deprecated = "Look at you big man using a deprecation message"]
// struct DeprecatedTypeWithMsg {
// a: i32,
// }

// #[derive(Type)]
// #[specta(export = false)]
// #[deprecated(note = "Look at you big man using a deprecation message")]
// struct DeprecatedTypeWithMsg2 {
// a: i32,
// }

// #[derive(Type)]
// #[specta(export = false)]
// struct DeprecatedFields {
// a: i32,
// // #[deprecated]
// b: String,
// #[deprecated = "This field is cringe!"]
// c: String,
// #[deprecated(note = "This field is cringe!")]
// d: String,
// }

0 comments on commit 5d0347a

Please sign in to comment.