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

fix: 57 rust options not generated #58

Merged
merged 4 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
55 changes: 37 additions & 18 deletions cli/src/languages/rust/__snapshots__/codegen-rust.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports[`rust codegen cache can generate also with model 1`] = `
"#![allow(dead_code)]
extern crate memorix_client_redis;

#[derive(Clone, memorix_client_redis::Serialize, memorix_client_redis::Deserialize)]
#[derive(Clone, memorix_client_redis::Serialize, memorix_client_redis::Deserialize, PartialEq, std::fmt::Debug)]
pub struct User {
pub name: String,
#[serde(skip_serializing_if = \\"Option::is_none\\")]
Expand All @@ -25,10 +25,12 @@ impl MemorixCache {
adminId: memorix_client_redis::MemorixCacheItemNoKey::new(
memorix_base.clone(),
\\"adminId\\".to_string(),
None
),
user: memorix_client_redis::MemorixCacheItem::new(
memorix_base.clone(),
\\"user\\".to_string(),
None
),
}
}
Expand Down Expand Up @@ -63,7 +65,7 @@ exports[`rust codegen cache can generate with inline object type 1`] = `
"#![allow(dead_code)]
extern crate memorix_client_redis;

#[derive(Clone, memorix_client_redis::Serialize, memorix_client_redis::Deserialize)]
#[derive(Clone, memorix_client_redis::Serialize, memorix_client_redis::Deserialize, PartialEq, std::fmt::Debug)]
pub struct CacheUserPayload {
pub name: String,
#[serde(skip_serializing_if = \\"Option::is_none\\")]
Expand All @@ -83,6 +85,7 @@ impl MemorixCache {
user: memorix_client_redis::MemorixCacheItem::new(
memorix_base.clone(),
\\"user\\".to_string(),
None
),
}
}
Expand Down Expand Up @@ -129,6 +132,7 @@ impl MemorixCache {
user: memorix_client_redis::MemorixCacheItem::new(
memorix_base.clone(),
\\"user\\".to_string(),
None
),
}
}
Expand Down Expand Up @@ -163,7 +167,7 @@ exports[`rust codegen cache can generate with inline types and convert to CamelC
"#![allow(dead_code)]
extern crate memorix_client_redis;

#[derive(Clone, memorix_client_redis::Serialize, memorix_client_redis::Deserialize)]
#[derive(Clone, memorix_client_redis::Serialize, memorix_client_redis::Deserialize, PartialEq, std::fmt::Debug)]
pub struct CacheUserByNumberPayload {
pub name: String,
pub age: i32,
Expand All @@ -182,6 +186,7 @@ impl MemorixCache {
user_by_number: memorix_client_redis::MemorixCacheItem::new(
memorix_base.clone(),
\\"user_by_number\\".to_string(),
None
),
}
}
Expand Down Expand Up @@ -216,7 +221,7 @@ exports[`rust codegen cache can generate with no key 1`] = `
"#![allow(dead_code)]
extern crate memorix_client_redis;

#[derive(Clone, memorix_client_redis::Serialize, memorix_client_redis::Deserialize)]
#[derive(Clone, memorix_client_redis::Serialize, memorix_client_redis::Deserialize, PartialEq, std::fmt::Debug)]
pub struct CacheUserPayload {
pub name: String,
#[serde(skip_serializing_if = \\"Option::is_none\\")]
Expand All @@ -236,6 +241,7 @@ impl MemorixCache {
user: memorix_client_redis::MemorixCacheItemNoKey::new(
memorix_base.clone(),
\\"user\\".to_string(),
None
),
}
}
Expand Down Expand Up @@ -282,6 +288,13 @@ impl MemorixCache {
user: memorix_client_redis::MemorixCacheItem::new(
memorix_base.clone(),
\\"user\\".to_string(),
Some(memorix_client_redis::MemorixOptionsCache {
expire: Some(memorix_client_redis::MemorixOptionsCacheExpire {
value: 5,
is_in_ms: None,
extend_on_get: Some(true),
}),
})
),
}
}
Expand Down Expand Up @@ -371,9 +384,9 @@ impl Memorix {
extend_on_get: Some(true),
}),
}),
task: MemorixTaskItem.Options(
take_newest=True,
),
task: Some(memorix_client_redis::MemorixOptionsTask {
take_newest: Some(true),
}),
})
).await?;
Ok(Self {
Expand Down Expand Up @@ -401,13 +414,13 @@ exports[`rust codegen model can generate from 2 models 1`] = `
"#![allow(dead_code)]
extern crate memorix_client_redis;

#[derive(Clone, memorix_client_redis::Serialize, memorix_client_redis::Deserialize)]
#[derive(Clone, memorix_client_redis::Serialize, memorix_client_redis::Deserialize, PartialEq, std::fmt::Debug)]
pub struct User1 {
pub id: i32,
}


#[derive(Clone, memorix_client_redis::Serialize, memorix_client_redis::Deserialize)]
#[derive(Clone, memorix_client_redis::Serialize, memorix_client_redis::Deserialize, PartialEq, std::fmt::Debug)]
pub struct User2 {
pub name: String,
#[serde(skip_serializing_if = \\"Option::is_none\\")]
Expand All @@ -419,7 +432,7 @@ exports[`rust codegen model can generate from model 1`] = `
"#![allow(dead_code)]
extern crate memorix_client_redis;

#[derive(Clone, memorix_client_redis::Serialize, memorix_client_redis::Deserialize)]
#[derive(Clone, memorix_client_redis::Serialize, memorix_client_redis::Deserialize, PartialEq, std::fmt::Debug)]
pub struct User {
pub id: i32,
pub name: String,
Expand All @@ -432,15 +445,15 @@ exports[`rust codegen model can generate from model with array 1`] = `
"#![allow(dead_code)]
extern crate memorix_client_redis;

#[derive(Clone, memorix_client_redis::Serialize, memorix_client_redis::Deserialize)]
#[derive(Clone, memorix_client_redis::Serialize, memorix_client_redis::Deserialize, PartialEq, std::fmt::Debug)]
pub struct UserChildren {
pub id: i32,
#[serde(skip_serializing_if = \\"Option::is_none\\")]
pub name: Option<String>,
}


#[derive(Clone, memorix_client_redis::Serialize, memorix_client_redis::Deserialize)]
#[derive(Clone, memorix_client_redis::Serialize, memorix_client_redis::Deserialize, PartialEq, std::fmt::Debug)]
pub struct User {
pub id: i32,
pub names: Vec<String>,
Expand All @@ -453,14 +466,14 @@ exports[`rust codegen model can generate from model within model 1`] = `
"#![allow(dead_code)]
extern crate memorix_client_redis;

#[derive(Clone, memorix_client_redis::Serialize, memorix_client_redis::Deserialize)]
#[derive(Clone, memorix_client_redis::Serialize, memorix_client_redis::Deserialize, PartialEq, std::fmt::Debug)]
pub struct UserPapa {
#[serde(skip_serializing_if = \\"Option::is_none\\")]
pub name: Option<String>,
}


#[derive(Clone, memorix_client_redis::Serialize, memorix_client_redis::Deserialize)]
#[derive(Clone, memorix_client_redis::Serialize, memorix_client_redis::Deserialize, PartialEq, std::fmt::Debug)]
pub struct User {
pub id: i32,
pub papa: UserPapa,
Expand All @@ -471,13 +484,13 @@ exports[`rust codegen model can generate from model within model within a model
"#![allow(dead_code)]
extern crate memorix_client_redis;

#[derive(Clone, memorix_client_redis::Serialize, memorix_client_redis::Deserialize)]
#[derive(Clone, memorix_client_redis::Serialize, memorix_client_redis::Deserialize, PartialEq, std::fmt::Debug)]
pub struct UserPapaMama {
pub sick: bool,
}


#[derive(Clone, memorix_client_redis::Serialize, memorix_client_redis::Deserialize)]
#[derive(Clone, memorix_client_redis::Serialize, memorix_client_redis::Deserialize, PartialEq, std::fmt::Debug)]
pub struct UserPapa {
#[serde(skip_serializing_if = \\"Option::is_none\\")]
pub name: Option<String>,
Expand All @@ -487,7 +500,7 @@ pub struct UserPapa {
}


#[derive(Clone, memorix_client_redis::Serialize, memorix_client_redis::Deserialize)]
#[derive(Clone, memorix_client_redis::Serialize, memorix_client_redis::Deserialize, PartialEq, std::fmt::Debug)]
pub struct User {
pub id: i32,
pub papa: UserPapa,
Expand All @@ -498,7 +511,7 @@ exports[`rust codegen namespace can generate 1`] = `
"#![allow(dead_code)]
extern crate memorix_client_redis;

#[derive(Clone, memorix_client_redis::Serialize, memorix_client_redis::Deserialize)]
#[derive(Clone, memorix_client_redis::Serialize, memorix_client_redis::Deserialize, PartialEq, std::fmt::Debug)]
pub struct UserCacheBioPayload {
pub description: String,
}
Expand All @@ -516,6 +529,7 @@ impl MemorixCacheUser {
bio: memorix_client_redis::MemorixCacheItemNoKey::new(
memorix_base.clone(),
\\"bio\\".to_string(),
None
),
}
}
Expand Down Expand Up @@ -567,6 +581,7 @@ impl MemorixCacheSpaceship {
bio: memorix_client_redis::MemorixCacheItemNoKey::new(
memorix_base.clone(),
\\"bio\\".to_string(),
None
),
}
}
Expand Down Expand Up @@ -696,6 +711,7 @@ impl MemorixTask {
doIt: memorix_client_redis::MemorixTaskItem::new(
memorix_base.clone(),
\\"doIt\\".to_string(),
None
),
}
}
Expand Down Expand Up @@ -742,6 +758,9 @@ impl MemorixTask {
doIt: memorix_client_redis::MemorixTaskItem::new(
memorix_base.clone(),
\\"doIt\\".to_string(),
Some(memorix_client_redis::MemorixOptionsTask {
take_newest: Some(true),
})
),
}
}
Expand Down
41 changes: 29 additions & 12 deletions cli/src/languages/rust/rust.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ const getTabs = (x: number) => get2Tabs(x * 2);

const blockOptionsToCode: (
blockType: BlockTypes,
options: MapValue<(BlockCache | BlockTask)["values"]>["options"],
level: number
) => string = (bType, options, level) => {
level: number,
options?: MapValue<(BlockCache | BlockTask)["values"]>["options"]
) => string = (bType, level, options) => {
if (!options) {
return "None";
}
switch (bType) {
case BlockTypes.cache: {
const o = options as MapValue<BlockCache["values"]>["options"];
Expand Down Expand Up @@ -50,9 +53,9 @@ ${getTabs(level)}})`
case BlockTypes.task: {
const o = options as MapValue<BlockTask["values"]>["options"];
return o
? `MemorixTaskItem.Options(
${getTabs(level + 1)}take_newest=${o.takeNewest ? "True" : "False"},
${getTabs(level)})`
? `Some(memorix_client_redis::MemorixOptionsTask {
${getTabs(level + 1)}take_newest: Some(${o.takeNewest ? "true" : "false"}),
${getTabs(level)}})`
: "None";
}
case BlockTypes.enum:
Expand Down Expand Up @@ -151,7 +154,7 @@ const blockToStruct: (block: Block) => string = (b) => {
const blockToCode: (block: Block) => string = (b) => {
switch (b.type) {
case BlockTypes.model:
return `#[derive(Clone, memorix_client_redis::Serialize, memorix_client_redis::Deserialize)]
return `#[derive(Clone, memorix_client_redis::Serialize, memorix_client_redis::Deserialize, PartialEq, std::fmt::Debug)]
pub struct ${b.name} {
${b.properties
.map(
Expand Down Expand Up @@ -200,7 +203,21 @@ ${b.values.map((v) => `${getTabs(1)}${v},`).join(`\n`)}
: ""
}::new(
${getTabs(4)}memorix_base.clone(),
${getTabs(4)}"${name}".to_string(),
${getTabs(4)}"${name}".to_string(),${
b.type === BlockTypes.cache || b.type === BlockTypes.task
? `
${getTabs(4)}${blockOptionsToCode(
b.type,
4,
{
[BlockTypes.cache]: (v as MapValue<BlockCache["values"]>)
.options,
[BlockTypes.task]: (v as MapValue<BlockTask["values"]>)
.options,
}[b.type]
)}`
: ""
}
${getTabs(3)}),`;
})
.join("\n")}`;
Expand All @@ -220,13 +237,13 @@ const defaultOptionsToCode: (defaultOptions?: DefaultOptions) => string = (
return `Some(memorix_client_redis::MemorixOptions {
${getTabs(4)}cache: ${blockOptionsToCode(
BlockTypes.cache,
defaultOptions.cache,
4
4,
defaultOptions.cache
)},
${getTabs(4)}task: ${blockOptionsToCode(
BlockTypes.task,
defaultOptions.task,
4
4,
defaultOptions.task
)},
${getTabs(3)}})`;
};
Expand Down
13 changes: 12 additions & 1 deletion clients/redis/rust/examples/example_schema_generated.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(dead_code)]
extern crate memorix_client_redis;

#[allow(non_camel_case_types, clippy::upper_case_acronyms)]
Expand All @@ -14,7 +15,13 @@ pub enum Animal {
person,
}

#[derive(Clone, memorix_client_redis::Serialize, memorix_client_redis::Deserialize)]
#[derive(
Clone,
memorix_client_redis::Serialize,
memorix_client_redis::Deserialize,
PartialEq,
std::fmt::Debug,
)]
pub struct User {
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -36,10 +43,12 @@ impl MemorixCacheBlaBla {
favoriteAnimal: memorix_client_redis::MemorixCacheItem::new(
memorix_base.clone(),
"favoriteAnimal".to_string(),
None,
),
user: memorix_client_redis::MemorixCacheItem::new(
memorix_base.clone(),
"user".to_string(),
None,
),
}
}
Expand Down Expand Up @@ -80,6 +89,7 @@ impl MemorixCache {
hello: memorix_client_redis::MemorixCacheItemNoKey::new(
memorix_base.clone(),
"hello".to_string(),
None,
),
}
}
Expand Down Expand Up @@ -114,6 +124,7 @@ impl MemorixTask {
runAlgo: memorix_client_redis::MemorixTaskItemNoKey::new(
memorix_base.clone(),
"runAlgo".to_string(),
None,
),
}
}
Expand Down
Loading
Loading