Skip to content

Commit ff0e56e

Browse files
authored
minor: Expire and fixes (#69)
* Did the thing * empty * Try again * format is cool * Again * Fixes * Fix tests * minor: try prerelease * Try again * Finalize version * Added runtime value check only when used * another prerelease * Fix rust * Add typing-extensions to python package * Some rust nicer fix * Fixe * revert release
1 parent 246381e commit ff0e56e

36 files changed

+1684
-794
lines changed

cli/scripts/create-dist.sh

Lines changed: 0 additions & 14 deletions
This file was deleted.

cli/scripts/fix-ts-path.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

cli/scripts/formula_template.rb

Lines changed: 0 additions & 24 deletions
This file was deleted.

cli/scripts/publish_homebrew_version.sh

Lines changed: 0 additions & 39 deletions
This file was deleted.

cli/scripts/update_package_version.sh

Lines changed: 0 additions & 2 deletions
This file was deleted.

cli/src/export_schema.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,18 @@ fn namespace_to_export_namespace(namespace: &Namespace, expose_all: bool) -> Exp
5858
namespaces: namespace
5959
.namespaces
6060
.iter()
61-
.map(|(k, n)| (k.clone(), namespace_to_export_namespace(n, expose_all)))
61+
.filter_map(|(k, n)| {
62+
let sub_namespace = namespace_to_export_namespace(n, expose_all);
63+
match sub_namespace.cache_items.len()
64+
+ sub_namespace.pubsub_items.len()
65+
+ sub_namespace.task_items.len()
66+
+ sub_namespace.enum_items.len()
67+
+ sub_namespace.type_items.len()
68+
{
69+
0 => None,
70+
_ => Some((k.clone(), sub_namespace)),
71+
}
72+
})
6273
.collect(),
6374
type_items: namespace
6475
.type_items

cli/src/languages/python.rs

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,19 @@ fn indent(level: usize) -> String {
1212
fn flat_type_item_to_code(
1313
flat_type_item: &FlatValidatedTypeItem,
1414
schema: &FlatValidatedSchema,
15+
no_squote: bool,
1516
) -> String {
1617
match flat_type_item {
17-
FlatValidatedTypeItem::Optional(x) => {
18-
format!("typing.Optional[{}]", flat_type_item_to_code(x, schema)).to_string()
19-
}
20-
FlatValidatedTypeItem::Array(x) => {
21-
format!("typing.List[{}]", flat_type_item_to_code(x, schema)).to_string()
22-
}
18+
FlatValidatedTypeItem::Optional(x) => format!(
19+
"typing.Optional[{}]",
20+
flat_type_item_to_code(x, schema, no_squote)
21+
)
22+
.to_string(),
23+
FlatValidatedTypeItem::Array(x) => format!(
24+
"typing.List[{}]",
25+
flat_type_item_to_code(x, schema, no_squote)
26+
)
27+
.to_string(),
2328
FlatValidatedTypeItem::Reference(x) => {
2429
let (namespace, namespace_names) = x.namespace_indexes.iter().fold(
2530
(&schema.global_namespace, Vec::<&str>::new()),
@@ -30,7 +35,12 @@ fn flat_type_item_to_code(
3035
},
3136
);
3237
format!(
33-
"{prefix}{seperator}{name}",
38+
"{squote}{prefix}{seperator}{name}{squote}",
39+
squote = match (no_squote, x.kind.clone()) {
40+
(false, FlatValidatedReferenceTypeItemKind::TypeObjectItem(_)) => "'",
41+
(false, FlatValidatedReferenceTypeItemKind::TypeItem(_)) => "'",
42+
_ => "",
43+
},
3444
prefix = namespace_names
3545
.iter()
3646
.map(|x| stringcase::pascal_case(x))
@@ -66,10 +76,8 @@ fn flat_type_item_to_code(
6676

6777
fn value_to_code(value: &Value) -> String {
6878
match value {
69-
Value::String(x) => format!("\"{x}\""),
70-
Value::Env(x) => {
71-
format!("os.environ[\"{x}\"]")
72-
}
79+
Value::String(x) => format!("Value.from_string(\"{x}\")"),
80+
Value::Env(x) => format!("Value.from_env_variable(\"{x}\")"),
7381
}
7482
}
7583

@@ -91,7 +99,7 @@ fn type_item_object_to_code(
9199
.iter()
92100
.map(|(property_name, flat_type_item)| format!(
93101
"{base_indent} {property_name}: {}",
94-
flat_type_item_to_code(flat_type_item, schema)
102+
flat_type_item_to_code(flat_type_item, schema, false)
95103
)
96104
.to_string())
97105
.collect::<Vec<_>>()
@@ -131,7 +139,7 @@ fn namespace_to_code(
131139
for (name, flat_type_item) in &namespace.flat_type_items {
132140
result.push_str(&format!(
133141
"{base_indent}{name} = {}\n\n",
134-
flat_type_item_to_code(flat_type_item, schema)
142+
flat_type_item_to_code(flat_type_item, schema, true)
135143
));
136144
}
137145
for (name, sub_namespace) in &namespace.namespaces {
@@ -165,20 +173,21 @@ fn namespace_to_code(
165173
.cache_items
166174
.iter()
167175
.map(|(name, item)| {
168-
let payload = flat_type_item_to_code(&item.payload, schema);
176+
let payload = flat_type_item_to_code(&item.payload, schema, false);
169177
format!(
170178
r#"{base_indent} self.{name} = MemorixCacheAll.Item{api}{key}](
171179
{base_indent} api=api,
172180
{base_indent} id="{name}",
173-
{base_indent} payload_class={payload},{options}
181+
{base_indent} payload_class={payload_no_squote},{options}
174182
{base_indent} )"#,
175183
key = match &item.key {
176184
None => format!("NoKey[{payload}"),
177185
Some(key) => {
178-
let key = flat_type_item_to_code(key, schema);
186+
let key = flat_type_item_to_code(key, schema, false);
179187
format!("[{key}, {payload}")
180188
}
181189
},
190+
payload_no_squote = flat_type_item_to_code(&item.payload, schema, true),
182191
api = ALL_CACHE_OPERATIONS
183192
.iter()
184193
.map(|x| match item.expose.contains(x) {
@@ -236,20 +245,21 @@ fn namespace_to_code(
236245
.pubsub_items
237246
.iter()
238247
.map(|(name, item)| {
239-
let payload = flat_type_item_to_code(&item.payload, schema);
248+
let payload = flat_type_item_to_code(&item.payload, schema, false);
240249
format!(
241250
r#"{base_indent} self.{name} = MemorixPubSubAll.Item{api}{key}](
242251
{base_indent} api=api,
243252
{base_indent} id="{name}",
244-
{base_indent} payload_class={payload},
253+
{base_indent} payload_class={payload_no_squote},
245254
{base_indent} )"#,
246255
key = match &item.key {
247256
None => format!("NoKey[{payload}"),
248257
Some(key) => {
249-
let key = flat_type_item_to_code(key, schema);
258+
let key = flat_type_item_to_code(key, schema, false);
250259
format!("[{key}, {payload}")
251260
}
252261
},
262+
payload_no_squote = flat_type_item_to_code(&item.payload, schema, true),
253263
api = ALL_PUBSUB_OPERATIONS
254264
.iter()
255265
.map(|x| match item.expose.contains(x) {
@@ -278,20 +288,21 @@ fn namespace_to_code(
278288
.task_items
279289
.iter()
280290
.map(|(name, item)| {
281-
let payload = flat_type_item_to_code(&item.payload, schema);
291+
let payload = flat_type_item_to_code(&item.payload, schema, false);
282292
format!(
283293
r#"{base_indent} self.{name} = MemorixTaskAll.Item{api}{key}](
284294
{base_indent} api=api,
285295
{base_indent} id="{name}",
286-
{base_indent} payload_class={payload},{options}
296+
{base_indent} payload_class={payload_no_squote},{options}
287297
{base_indent} )"#,
288298
key = match &item.key {
289299
None => format!("NoKey[{payload}"),
290300
Some(key) => {
291-
let key = flat_type_item_to_code(key, schema);
301+
let key = flat_type_item_to_code(key, schema, false);
292302
format!("[{key}, {payload}")
293303
}
294304
},
305+
payload_no_squote = flat_type_item_to_code(&item.payload, schema, true),
295306
api = ALL_TASK_OPERATIONS
296307
.iter()
297308
.map(|x| match item.expose.contains(x) {
@@ -413,6 +424,7 @@ from memorix_client_redis import (
413424
MemorixCacheAll,
414425
MemorixPubSubAll,
415426
MemorixTaskAll,
427+
Value,
416428
)
417429
418430
{}"#,

cli/src/languages/rust.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,8 @@ fn flat_type_item_to_code(
5757

5858
fn value_to_code(value: &Value) -> String {
5959
match value {
60-
Value::String(x) => format!("\"{x}\".to_string()"),
61-
Value::Env(x) => {
62-
format!("std::env::var(\"{x}\").expect(\"missing environment variable {x}\")")
63-
}
60+
Value::String(x) => format!("memorix_client_redis::Value::from_string(\"{x}\")"),
61+
Value::Env(x) => format!("memorix_client_redis::Value::from_env_variable(\"{x}\")"),
6462
}
6563
}
6664

@@ -426,7 +424,7 @@ fn namespace_to_code(
426424
.join("\n\n"),
427425
impl_new = match name_tree.is_empty() {
428426
true => format!(r#"{base_indent} pub async fn new() -> Result<Memorix, Box<dyn std::error::Error + Sync + Send>> {{
429-
{base_indent} let memorix_base = memorix_client_redis::MemorixBase::new(
427+
{base_indent} let _memorix_base = memorix_client_redis::MemorixBase::new(
430428
{base_indent} {redis_url},
431429
{base_indent} MEMORIX_NAMESPACE_NAME_TREE,
432430
{base_indent} )
@@ -437,7 +435,7 @@ fn namespace_to_code(
437435
r#"{base_indent} pub fn new(
438436
{base_indent} other: memorix_client_redis::MemorixBase,
439437
{base_indent} ) -> Result<Memorix, Box<dyn std::error::Error + Sync + Send>> {{
440-
{base_indent} let memorix_base = memorix_client_redis::MemorixBase::from(
438+
{base_indent} let _memorix_base = memorix_client_redis::MemorixBase::from(
441439
{base_indent} other,
442440
{base_indent} MEMORIX_NAMESPACE_NAME_TREE,
443441
{base_indent} );"#),
@@ -447,20 +445,20 @@ fn namespace_to_code(
447445
.namespaces
448446
.iter()
449447
.map(|(name, _)| format!(
450-
"{base_indent} {name}: {namespace_name}::Memorix::new(memorix_base.clone())?,",
448+
"{base_indent} {name}: {namespace_name}::Memorix::new(_memorix_base.clone())?,",
451449
namespace_name = stringcase::snake_case(name),
452450
))
453451
.collect::<Vec<_>>()
454452
.join("\n"),
455453
[
456454
(!namespace.cache_items.is_empty()).then(|| format!(
457-
"{base_indent} cache: MemorixCache::new(memorix_base.clone())?,"
455+
"{base_indent} cache: MemorixCache::new(_memorix_base.clone())?,"
458456
)),
459457
(!namespace.pubsub_items.is_empty()).then(|| format!(
460-
"{base_indent} pubsub: MemorixPubSub::new(memorix_base.clone())?,"
458+
"{base_indent} pubsub: MemorixPubSub::new(_memorix_base.clone())?,"
461459
)),
462460
(!namespace.task_items.is_empty()).then(|| format!(
463-
"{base_indent} task: MemorixTask::new(memorix_base.clone())?,"
461+
"{base_indent} task: MemorixTask::new(_memorix_base.clone())?,"
464462
)),
465463
]
466464
.into_iter()

cli/src/languages/typescript.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,11 @@ fn type_item_to_code(
6262

6363
fn value_to_code(value: &Value) -> String {
6464
match value {
65-
Value::String(x) => format!("\"{x}\""),
65+
Value::String(x) => {
66+
format!("getStringValue(\"{x}\")")
67+
}
6668
Value::Env(x) => {
67-
format!("getEnvVariable(\"{x}\")")
69+
format!("getEnvVariableValue(\"{x}\")")
6870
}
6971
}
7072
}
@@ -304,7 +306,7 @@ pub fn codegen(schema: &ValidatedSchema) -> String {
304306
r#"// deno-fmt-ignore-file
305307
// deno-lint-ignore-file
306308
/* eslint-disable */
307-
import {{ MemorixBase, getEnvVariable }} from "@memorix/client-redis";
309+
import {{ MemorixBase, getStringValue, getEnvVariableValue }} from "@memorix/client-redis";
308310
309311
{}"#,
310312
namespace_to_code(&schema.global_namespace, vec![], schema)

cli/src/parser.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ pub enum CacheOperation {
204204
Get,
205205
Set,
206206
Delete,
207+
Expire,
207208
}
208209
pub ALL_CACHE_OPERATIONS
209210
}
@@ -212,7 +213,8 @@ impl_from_and_to_sdl_for_enum!(
212213
CacheOperation,
213214
Get => "get",
214215
Set => "set",
215-
Delete => "delete"
216+
Delete => "delete",
217+
Expire => "expire"
216218
);
217219

218220
create_enum_with_const_slice! {

0 commit comments

Comments
 (0)