From f22d27643c03709ecc7971a2bbede9fd353950fc Mon Sep 17 00:00:00 2001 From: iamwacko Date: Fri, 20 Jan 2023 07:40:16 -0800 Subject: [PATCH 01/40] feat: start work on uuid --- core/Cargo.toml | 4 ++-- core/src/graph/json.rs | 1 + core/src/graph/mod.rs | 11 ++++++++++- core/src/graph/string/mod.rs | 9 --------- core/src/graph/string/uuid.rs | 15 --------------- core/src/graph/uuid.rs | 13 +++++++++++++ core/src/schema/content/mod.rs | 2 +- core/src/schema/content/string.rs | 6 ------ core/src/schema/inference/mod.rs | 1 - 9 files changed, 27 insertions(+), 35 deletions(-) delete mode 100644 core/src/graph/string/uuid.rs create mode 100644 core/src/graph/uuid.rs diff --git a/core/Cargo.toml b/core/Cargo.toml index ec00e1a1..ffbc13e2 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -29,11 +29,11 @@ bincode = "1.3.1" num = { version = "0.4.0", features = [ "rand" ] } rand_regex = "0.15.1" synth-gen = { path = "../gen", features = [ "shared" ] } -uuid = { version = "0.8.2", features = ["v4"] } +uuid = { version = "0.8.2", features = ["v4", "serde"] } bimap = { version = "0.6.0", features = [ "std" ] } humantime-serde = "1.0.1" bloomfilter = "1.0.5" dynfmt = { version = "0.1.5", features = [ "curly" ] } -sqlx = { version = "0.6", features = ["postgres", "mysql", "runtime-async-std-rustls", "decimal", "chrono"] } +sqlx = { version = "0.6", features = ["postgres", "mysql", "runtime-async-std-rustls", "decimal", "chrono", "uuid"] } uriparse = "0.6.3" paste = "1.0" diff --git a/core/src/graph/json.rs b/core/src/graph/json.rs index 214ab909..7906ef2d 100644 --- a/core/src/graph/json.rs +++ b/core/src/graph/json.rs @@ -9,6 +9,7 @@ pub fn synth_val_to_json(val: Value) -> serde_json::Value { Value::Bool(b) => serde_json::Value::Bool(b), Value::Number(n) => serde_json::Value::Number(synth_num_to_json(n)), Value::String(s) => serde_json::Value::String(s), + Value::Uuid(u) => serde_json::Value::String(u.to_hyphenated().to_string()), Value::DateTime(dt) => serde_json::Value::String(dt.format_to_string()), Value::Object(obj) => serde_json::Value::Object(synth_obj_to_json(obj)), Value::Array(arr) => serde_json::Value::Array(synth_arr_to_json(arr)), diff --git a/core/src/graph/mod.rs b/core/src/graph/mod.rs index f7626312..88430023 100644 --- a/core/src/graph/mod.rs +++ b/core/src/graph/mod.rs @@ -3,6 +3,7 @@ use std::collections::BTreeMap; use anyhow::{Context, Result}; +use ::uuid::Uuid; use chrono::{DateTime, FixedOffset, NaiveDate, NaiveDateTime, NaiveTime, Utc}; use sqlx::mysql::MySqlTypeInfo; use sqlx::postgres::{PgArgumentBuffer, PgTypeInfo}; @@ -23,7 +24,10 @@ pub mod null; pub use null::NullNode; pub mod string; -pub use string::{Format, FormatArgs, RandFaker, RandomString, StringNode, Truncated, UuidGen}; +pub use string::{Format, FormatArgs, RandFaker, RandomString, StringNode, Truncated}; + +pub mod uuid; +pub use self::uuid::UuidNode; pub mod date_time; pub use date_time::{DateTimeNode, RandomDateTime}; @@ -161,6 +165,7 @@ derive_from! { Bool(bool), Number(Number), String(String), + Uuid(Uuid), DateTime(ChronoValueAndFormat), Object(BTreeMap), Array(Vec), @@ -397,6 +402,7 @@ impl Value { Self::Object(_) => { serde_json::to_string(&json::synth_val_to_json(self.clone())).unwrap() } + Self::Uuid(uid) => uid.to_hyphenated().to_string(), } } @@ -409,6 +415,7 @@ impl Value { // Based on https://docs.rs/sqlx-core/0.5.9/sqlx_core/postgres/types/index.html while let Some(c) = current { let pair = match c { + Value::Uuid(_) => (None, "uuid"), Value::Null(_) => (None, "unknown"), Value::Bool(_) => (None, "bool"), Value::Number(num) => match *num { @@ -553,6 +560,7 @@ impl Encode<'_, MySql> for Value { buf, ), Value::Array(_arr) => todo!(), // as Encode<'_, MySql>>::encode_by_ref(arr, buf), //TODO special-case for u8 arrays? + Value::Uuid(u) => todo!(), } } @@ -777,6 +785,7 @@ derive_generator!( DateTime(DateTimeNode), Object(ObjectNode), Array(ArrayNode), + Uuid(UuidNode), OneOf(OneOfNode), Series(SeriesNode), Unique(UniqueNode), diff --git a/core/src/graph/string/mod.rs b/core/src/graph/string/mod.rs index 553bfa7d..7c31fbba 100644 --- a/core/src/graph/string/mod.rs +++ b/core/src/graph/string/mod.rs @@ -8,9 +8,7 @@ pub mod format; pub mod serialized; pub mod sliced; pub mod truncated; -pub mod uuid; -pub use self::uuid::UuidGen; pub use constant::Constant; pub use faker::{FakerArgs, Locale, RandFaker}; pub use format::{Format, FormatArgs}; @@ -26,7 +24,6 @@ derive_generator! { Faker(TryOnce), Serialized(TryOnce) Categorical(OnceInfallible>>) - Uuid(OnceInfallible), Format(Format), Truncated(Truncated), Sliced(Sliced), @@ -58,12 +55,6 @@ impl From> for RandomString { } } -impl From for RandomString { - fn from(uuid: UuidGen) -> Self { - Self::Uuid(uuid.infallible().try_once()) - } -} - impl From for RandomString { fn from(trunc: Truncated) -> Self { Self::Truncated(trunc) diff --git a/core/src/graph/string/uuid.rs b/core/src/graph/string/uuid.rs deleted file mode 100644 index 54a10842..00000000 --- a/core/src/graph/string/uuid.rs +++ /dev/null @@ -1,15 +0,0 @@ -use crate::graph::prelude::{Generator, GeneratorState, Rng}; -use synth_gen::Never; -use uuid::Uuid; - -pub struct UuidGen {} - -impl Generator for UuidGen { - type Yield = String; - type Return = Never; - - fn next(&mut self, rng: &mut R) -> GeneratorState { - let uuid = Uuid::from_u128(rng.gen()); - GeneratorState::Yielded(uuid.to_hyphenated().to_string()) - } -} diff --git a/core/src/graph/uuid.rs b/core/src/graph/uuid.rs new file mode 100644 index 00000000..d43c0615 --- /dev/null +++ b/core/src/graph/uuid.rs @@ -0,0 +1,13 @@ +use super::prelude::*; +use uuid::Uuid; + +pub struct UuidNode(); + +impl Generator for UuidNode { + type Yield = Token; + type Return = Result; + + fn next(&mut self, rng: &mut R) -> GeneratorState { + GeneratorState::Complete(Ok(Value::Uuid(Uuid::from_u128(rng.gen())))) + } +} diff --git a/core/src/schema/content/mod.rs b/core/src/schema/content/mod.rs index 5f0ee07e..541b5ab0 100644 --- a/core/src/schema/content/mod.rs +++ b/core/src/schema/content/mod.rs @@ -30,7 +30,7 @@ pub use number::{number_content, NumberContent, NumberContentKind, NumberKindExt mod string; pub use string::{ ConstantContent, FakerContent, FakerContentArgument, FormatContent, RegexContent, - SlicedContent, StringContent, Uuid, + SlicedContent, StringContent, }; mod date_time; diff --git a/core/src/schema/content/string.rs b/core/src/schema/content/string.rs index 0c7ebc4d..3e4f3e5e 100644 --- a/core/src/schema/content/string.rs +++ b/core/src/schema/content/string.rs @@ -13,16 +13,12 @@ pub enum StringContent { Faker(FakerContent), Categorical(Categorical), Serialized(SerializedContent), - Uuid(Uuid), Truncated(TruncatedContent), Sliced(SlicedContent), Format(FormatContent), Constant(ConstantContent), } -#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)] -pub struct Uuid; - impl StringContent { pub fn kind(&self) -> String { match self { @@ -30,7 +26,6 @@ impl StringContent { Self::Faker(faker) => faker.kind(), Self::Categorical(_) => "categorical".to_string(), Self::Serialized(_) => "serialized".to_string(), - Self::Uuid(_) => "uuid".to_string(), Self::Truncated(_) => "truncated".to_string(), Self::Sliced(_) => "sliced".to_string(), Self::Constant(_) => "constant".to_string(), @@ -352,7 +347,6 @@ impl Compile for StringContent { StringContent::Constant(ConstantContent(s)) => { RandomString::from(Constant(s.into())).into() } - StringContent::Uuid(_uuid) => RandomString::from(UuidGen {}).into(), }; Ok(Graph::String(string_node)) } diff --git a/core/src/schema/inference/mod.rs b/core/src/schema/inference/mod.rs index 842736d9..510aae57 100644 --- a/core/src/schema/inference/mod.rs +++ b/core/src/schema/inference/mod.rs @@ -126,7 +126,6 @@ impl MergeStrategy for OptionalMergeStrategy { } StringContent::Faker(_) => Ok(()), StringContent::Serialized(_) => Ok(()), // we can probably do better here - StringContent::Uuid(_) => Ok(()), StringContent::Truncated(_) => Ok(()), StringContent::Sliced(_) => Ok(()), StringContent::Constant(_) => Ok(()), From f3626834a1d595c026c4aa6db1c3bddc5b5fc1ac Mon Sep 17 00:00:00 2001 From: iamwacko Date: Fri, 20 Jan 2023 23:54:26 -0800 Subject: [PATCH 02/40] feat: more work on uuid --- Cargo.lock | 19 +++++++++++++++---- core/Cargo.toml | 2 +- core/src/graph/json.rs | 2 +- core/src/graph/mod.rs | 6 ++++-- core/src/schema/content/mod.rs | 5 +++++ core/src/schema/content/uuid.rs | 19 +++++++++++++++++++ synth/src/datasource/postgres_datasource.rs | 3 ++- 7 files changed, 47 insertions(+), 9 deletions(-) create mode 100644 core/src/schema/content/uuid.rs diff --git a/Cargo.lock b/Cargo.lock index 3cb5f697..fb89f3b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -579,7 +579,7 @@ dependencies = [ "serde", "serde_bytes", "serde_json", - "uuid", + "uuid 0.8.2", ] [[package]] @@ -2024,7 +2024,7 @@ dependencies = [ "trust-dns-proto", "trust-dns-resolver", "typed-builder", - "uuid", + "uuid 0.8.2", "version_check", "webpki 0.21.4", "webpki-roots 0.21.1", @@ -3213,6 +3213,7 @@ dependencies = [ "stringprep", "thiserror", "url", + "uuid 1.2.2", "webpki-roots 0.22.5", "whoami", ] @@ -3422,7 +3423,7 @@ dependencies = [ "tempfile", "test_macros", "uriparse", - "uuid", + "uuid 0.8.2", ] [[package]] @@ -3453,7 +3454,7 @@ dependencies = [ "synth-gen", "tempfile", "uriparse", - "uuid", + "uuid 1.2.2", ] [[package]] @@ -3931,6 +3932,16 @@ dependencies = [ "getrandom 0.2.3", ] +[[package]] +name = "uuid" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "422ee0de9031b5b948b97a8fc04e3aa35230001a722ddd27943e0be31564ce4c" +dependencies = [ + "getrandom 0.2.3", + "serde", +] + [[package]] name = "value-bag" version = "1.0.0-alpha.7" diff --git a/core/Cargo.toml b/core/Cargo.toml index ffbc13e2..8dbdf7f7 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -29,7 +29,7 @@ bincode = "1.3.1" num = { version = "0.4.0", features = [ "rand" ] } rand_regex = "0.15.1" synth-gen = { path = "../gen", features = [ "shared" ] } -uuid = { version = "0.8.2", features = ["v4", "serde"] } +uuid = { version = "1.2.2", features = ["v4", "serde"] } bimap = { version = "0.6.0", features = [ "std" ] } humantime-serde = "1.0.1" bloomfilter = "1.0.5" diff --git a/core/src/graph/json.rs b/core/src/graph/json.rs index 7906ef2d..2b35ce9e 100644 --- a/core/src/graph/json.rs +++ b/core/src/graph/json.rs @@ -9,7 +9,7 @@ pub fn synth_val_to_json(val: Value) -> serde_json::Value { Value::Bool(b) => serde_json::Value::Bool(b), Value::Number(n) => serde_json::Value::Number(synth_num_to_json(n)), Value::String(s) => serde_json::Value::String(s), - Value::Uuid(u) => serde_json::Value::String(u.to_hyphenated().to_string()), + Value::Uuid(u) => serde_json::Value::String(u.hyphenated().to_string()), Value::DateTime(dt) => serde_json::Value::String(dt.format_to_string()), Value::Object(obj) => serde_json::Value::Object(synth_obj_to_json(obj)), Value::Array(arr) => serde_json::Value::Array(synth_arr_to_json(arr)), diff --git a/core/src/graph/mod.rs b/core/src/graph/mod.rs index 88430023..5d6fa125 100644 --- a/core/src/graph/mod.rs +++ b/core/src/graph/mod.rs @@ -402,7 +402,7 @@ impl Value { Self::Object(_) => { serde_json::to_string(&json::synth_val_to_json(self.clone())).unwrap() } - Self::Uuid(uid) => uid.to_hyphenated().to_string(), + Self::Uuid(uid) => uid.hyphenated().to_string(), } } @@ -508,6 +508,7 @@ impl Encode<'_, Postgres> for Value { json::synth_val_to_json(self.clone()), buf, ), + Value::Uuid(u) => >::encode_by_ref(u, buf), Value::Array(_) => { let s = self.to_postgres_string(); >::encode_by_ref(&s, buf) @@ -560,7 +561,7 @@ impl Encode<'_, MySql> for Value { buf, ), Value::Array(_arr) => todo!(), // as Encode<'_, MySql>>::encode_by_ref(arr, buf), //TODO special-case for u8 arrays? - Value::Uuid(u) => todo!(), + Value::Uuid(u) => >::encode_by_ref(u, buf), } } @@ -591,6 +592,7 @@ impl Encode<'_, MySql> for Value { ChronoValue::DateTime(_) => as Type>::type_info(), }, Value::String(_) => >::type_info(), + Value::Uuid(_) => >::type_info(), Value::Object(_) => return None, //TODO: Use JSON here? Value::Array(elems) => { if elems.is_empty() { diff --git a/core/src/schema/content/mod.rs b/core/src/schema/content/mod.rs index 541b5ab0..c38a8cfb 100644 --- a/core/src/schema/content/mod.rs +++ b/core/src/schema/content/mod.rs @@ -44,6 +44,9 @@ pub use array::ArrayContent; mod object; pub use object::ObjectContent; +mod uuid; +pub use self::uuid::UuidContent; + mod datasource; pub use datasource::DatasourceContent; @@ -305,6 +308,7 @@ content! { labels: ContentLabels, variants: { Null(NullContent) => None, + Uuid(UuidContent) => None, Bool(BoolContent) => "missing a subtype. Try adding `constant`, or `frequency`", Number(NumberContent) => "missing a subtype. Try adding `constant`, `range`, or `id`", String(StringContent) => "missing a subtype. Try adding `pattern`, `faker`, `categorical`, `serialized`, `uuid`, `truncated`, or `format`", @@ -632,6 +636,7 @@ impl Compile for Content { Self::Object(object_content) => object_content.compile(compiler), Self::Bool(bool_content) => bool_content.compile(compiler), Self::String(string_content) => string_content.compile(compiler), + Self::Uuid(uuid_content) => uuid_content.compile(compiler), Self::DateTime(date_time_content) => date_time_content.compile(compiler), Self::Number(number_content) => number_content.compile(compiler), Self::Array(array_content) => array_content.compile(compiler), diff --git a/core/src/schema/content/uuid.rs b/core/src/schema/content/uuid.rs new file mode 100644 index 00000000..dfd4848d --- /dev/null +++ b/core/src/schema/content/uuid.rs @@ -0,0 +1,19 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Default, Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)] +#[serde(rename_all = "snake_case")] +#[serde(deny_unknown_fields)] +pub struct UuidContent {} + +impl UuidContent { + pub fn kind(&self) -> String { + "uuid".to_string() + } +} + +impl Compile for UuidContent { + fn compile<'a, C: Compiler<'a>>(&'a self, mut compiler: C) -> Result { + let node = UuidNode(); + Ok(Graph::Uuid(node)) + } +} diff --git a/synth/src/datasource/postgres_datasource.rs b/synth/src/datasource/postgres_datasource.rs index d73794b0..c0aeca51 100644 --- a/synth/src/datasource/postgres_datasource.rs +++ b/synth/src/datasource/postgres_datasource.rs @@ -15,7 +15,8 @@ use std::convert::TryFrom; use synth_core::schema::number_content::{F32, F64, I16, I32, I64}; use synth_core::schema::{ ArrayContent, BoolContent, Categorical, ChronoValue, ChronoValueAndFormat, ChronoValueType, - DateTimeContent, NumberContent, ObjectContent, RangeStep, RegexContent, StringContent, Uuid, + DateTimeContent, NumberContent, ObjectContent, RangeStep, RegexContent, StringContent, + UuidContent, }; use synth_core::{Content, Value}; From 132082831c85a1995ffb2167fcb91d5aa87b0099 Mon Sep 17 00:00:00 2001 From: iamwacko Date: Sat, 21 Jan 2023 07:31:25 -0800 Subject: [PATCH 03/40] fix: use preludes --- core/src/schema/content/uuid.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/src/schema/content/uuid.rs b/core/src/schema/content/uuid.rs index dfd4848d..d285ff2d 100644 --- a/core/src/schema/content/uuid.rs +++ b/core/src/schema/content/uuid.rs @@ -1,3 +1,5 @@ +use super::prelude::*; + use serde::{Deserialize, Serialize}; #[derive(Default, Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)] From ffd61786e2671d566002d284be9cdb19b6e0ad93 Mon Sep 17 00:00:00 2001 From: iamwacko Date: Sat, 21 Jan 2023 07:37:53 -0800 Subject: [PATCH 04/40] fix: underscores and non-exhaustive patterns --- core/src/schema/content/mod.rs | 1 + core/src/schema/content/uuid.rs | 8 +------- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/core/src/schema/content/mod.rs b/core/src/schema/content/mod.rs index c38a8cfb..02b4c809 100644 --- a/core/src/schema/content/mod.rs +++ b/core/src/schema/content/mod.rs @@ -502,6 +502,7 @@ impl Content { pub fn kind(&self) -> String { match self { + Content::Uuid(_) => "uuid".to_string(), Content::Null(_) => "null".to_string(), Content::Bool(content) => format!("bool::{}", content.kind()), Content::Number(content) => format!("number::{}", content.kind()), diff --git a/core/src/schema/content/uuid.rs b/core/src/schema/content/uuid.rs index d285ff2d..a2721d0f 100644 --- a/core/src/schema/content/uuid.rs +++ b/core/src/schema/content/uuid.rs @@ -7,14 +7,8 @@ use serde::{Deserialize, Serialize}; #[serde(deny_unknown_fields)] pub struct UuidContent {} -impl UuidContent { - pub fn kind(&self) -> String { - "uuid".to_string() - } -} - impl Compile for UuidContent { - fn compile<'a, C: Compiler<'a>>(&'a self, mut compiler: C) -> Result { + fn compile<'a, C: Compiler<'a>>(&'a self, mut _compiler: C) -> Result { let node = UuidNode(); Ok(Graph::Uuid(node)) } From 1879e271e39d1bc594893bf4367fb17757aeecf9 Mon Sep 17 00:00:00 2001 From: iamwacko Date: Sat, 21 Jan 2023 07:42:07 -0800 Subject: [PATCH 05/40] fix: clippy complaints --- core/src/schema/scenario.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/core/src/schema/scenario.rs b/core/src/schema/scenario.rs index b30652d1..c519b245 100644 --- a/core/src/schema/scenario.rs +++ b/core/src/schema/scenario.rs @@ -77,7 +77,6 @@ impl Scenario { .namespace .keys() .map(ToOwned::to_owned) - .into_iter() .filter(|c| !scenario_collections.contains(&c.as_str())) .collect(); From 69b7bafb181ece5fdfa2df25906945cc5bb7c7b7 Mon Sep 17 00:00:00 2001 From: iamwacko Date: Sat, 21 Jan 2023 07:46:49 -0800 Subject: [PATCH 06/40] fix: datasource --- synth/src/datasource/postgres_datasource.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synth/src/datasource/postgres_datasource.rs b/synth/src/datasource/postgres_datasource.rs index c0aeca51..2fcd78d6 100644 --- a/synth/src/datasource/postgres_datasource.rs +++ b/synth/src/datasource/postgres_datasource.rs @@ -233,7 +233,7 @@ impl SqlxDataSource for PostgresDataSource { skip_when_null: false, fields: BTreeMap::new(), }), - "uuid" => Content::String(StringContent::Uuid(Uuid)), + "uuid" => Content::Uuid(UuidContent {}), _ => { if let Some(data_type) = column_info.data_type.strip_prefix('_') { let mut column_info = column_info.clone(); From 7e4d320130ae500fa753faa8a5d04ad11ef6423c Mon Sep 17 00:00:00 2001 From: iamwacko Date: Sat, 21 Jan 2023 11:52:16 -0800 Subject: [PATCH 07/40] fix: non-exhaustive patterns --- synth/src/cli/csv/mod.rs | 1 + synth/src/cli/mongo.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/synth/src/cli/csv/mod.rs b/synth/src/cli/csv/mod.rs index cf048189..51eda2a0 100644 --- a/synth/src/cli/csv/mod.rs +++ b/synth/src/cli/csv/mod.rs @@ -308,6 +308,7 @@ fn to_csv_string(collection_name: String, value: Value, namespace: &Namespace) - fn synth_val_to_csv_record(val: Value, content: &Content, namespace: &Namespace) -> Vec { match val { + Value::Uuid(u) => vec![u.hyphenated().to_string()], Value::Null(_) => vec![String::new()], Value::Bool(b) => vec![b.to_string()], Value::Number(n) => { diff --git a/synth/src/cli/mongo.rs b/synth/src/cli/mongo.rs index be7b1891..c717a4df 100644 --- a/synth/src/cli/mongo.rs +++ b/synth/src/cli/mongo.rs @@ -211,6 +211,7 @@ impl MongoExportStrategy { fn value_to_bson(value: Value) -> Bson { match value { + Value::Uuid(u) => Bson::String(u.hyphenated().to_string()), Value::Null(_) => Bson::Null, Value::Bool(b) => Bson::Boolean(b), Value::Number(n) => number_to_bson(n), From b40afb5d3432e6efc782e431a6b30c7e416a558b Mon Sep 17 00:00:00 2001 From: iamwacko Date: Sat, 21 Jan 2023 11:58:59 -0800 Subject: [PATCH 08/40] chore: clippy --- core/src/graph/iter.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/graph/iter.rs b/core/src/graph/iter.rs index b60d58fb..cceafc36 100644 --- a/core/src/graph/iter.rs +++ b/core/src/graph/iter.rs @@ -29,7 +29,7 @@ mod tests { #[test] fn generator() { - let iter = (1..2).into_iter().map(|i| Value::Number(i.into())); + let iter = (1..2).map(|i| Value::Number(i.into())); let mut graph = Graph::Iter(IterNode { iter: Box::new(iter), @@ -49,7 +49,7 @@ mod tests { #[test] fn generator_cycle() { - let iter = (1..2).into_iter().map(|i| Value::Number(i.into())).cycle(); + let iter = (1..2).map(|i| Value::Number(i.into())).cycle(); let mut graph = Graph::Iter(IterNode { iter: Box::new(iter), From 88c1bd626e98322c23563bb5e54e7d8220cb446f Mon Sep 17 00:00:00 2001 From: iamwacko Date: Sat, 21 Jan 2023 12:13:32 -0800 Subject: [PATCH 09/40] docs: changed UUID to be seperate --- docs/docs/content/index.md | 5 ++--- docs/docs/content/string.md | 3 +-- docs/docs/content/toc.md | 3 +-- docs/docs/content/uuid.md | 13 +++++++++++++ docs/sidebars.js | 2 +- 5 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 docs/docs/content/uuid.md diff --git a/docs/docs/content/index.md b/docs/docs/content/index.md index 08ea6614..59ef0f8e 100644 --- a/docs/docs/content/index.md +++ b/docs/docs/content/index.md @@ -9,6 +9,7 @@ Synth has the following types of generators: * [null](null) generates as many nulls as you ever want * [bool](bool) generates `true` or `false`, either constant or following a given percentage +* [uuid](uuid) generates UUIDs * [number](number) generates ranges, distributions or series of [integer or floating-point](number#subtype) numbers * [series](series) generates streams of events (e.g. for logs) @@ -20,8 +21,6 @@ following a given percentage various classes of string: * [pattern](string#pattern) takes a regular expression and generates matching strings - * [uuid](string#uuid) generates hyphenated UUIDs - optionally with time zone * [faker](string#faker) has a large number of generators for names, contact information, credit card numbers, sentences, and much more * [format](string#format) combines multiple generators to one @@ -50,4 +49,4 @@ like a file * [one_of](one-of) allows you to choose from a set of contained generators * [same_as](same-as) creates a reference to another field in this or - another collection \ No newline at end of file + another collection diff --git a/docs/docs/content/string.md b/docs/docs/content/string.md index 4878efa9..7e2d8523 100644 --- a/docs/docs/content/string.md +++ b/docs/docs/content/string.md @@ -25,8 +25,7 @@ This generator has no parameters. ```json synth { - "type": "string", - "uuid": {} + "type": "uuid", } ``` diff --git a/docs/docs/content/toc.md b/docs/docs/content/toc.md index 7e18c563..de9e6a0a 100644 --- a/docs/docs/content/toc.md +++ b/docs/docs/content/toc.md @@ -22,6 +22,7 @@ another collection * [null](/content/null) generates as many nulls as you ever want * [bool](/content/bool) generates `true` or `false`, either constant or following a given percentage +* [uuid](/content/uuid) generates UUIDs * [number](/content/number) generates ranges, distributions or series of [integer or floating-point](/content/number#subtype) numbers * [series](/content/series) generates streams of events (e.g. for logs) @@ -33,8 +34,6 @@ following a given percentage various classes of string: * [pattern](/content/string#pattern) takes a regular expression and generates matching strings - * [uuid](/content/string#uuid) generates hyphenated UUIDs - optionally with time zone * [faker](/content/string#faker) has a large number of generators for names, contact information, credit card numbers, sentences, and much more * [format](/content/string#format) combines multiple generators to one diff --git a/docs/docs/content/uuid.md b/docs/docs/content/uuid.md new file mode 100644 index 00000000..79c758f6 --- /dev/null +++ b/docs/docs/content/uuid.md @@ -0,0 +1,13 @@ +## uuid + +`uuid` generates hyphenated [UUIDs](https://en.wikipedia.org/wiki/Universally_unique_identifier). + +This generator has no parameters. + +#### Example + +```json synth +{ + "type": "uuid", +} +``` diff --git a/docs/sidebars.js b/docs/sidebars.js index 3dc5ef52..5f5dfe77 100644 --- a/docs/sidebars.js +++ b/docs/sidebars.js @@ -4,7 +4,7 @@ module.exports = { "Examples": ['examples/bank'], "Tutorials": ['tutorials/creating-logs-with-synth'], "Integrations": ['integrations/index', 'integrations/postgres', 'integrations/mysql'], - "Generators": ['content/index', 'content/modifiers', 'content/null', 'content/bool', 'content/number', 'content/string', 'content/date-time', 'content/object', 'content/array', 'content/one-of', 'content/same-as', 'content/unique', 'content/series', 'content/datasource'], + "Generators": ['content/index', 'content/modifiers', 'content/null', 'content/bool', 'content/uuid', 'content/number', 'content/string', 'content/date-time', 'content/object', 'content/array', 'content/one-of', 'content/same-as', 'content/unique', 'content/series', 'content/datasource'], "Other": ['other/telemetry'] }, }; From 6f3fcb9e0a5f6ab474db7b7a668df01af473ca91 Mon Sep 17 00:00:00 2001 From: iamwacko Date: Sat, 21 Jan 2023 12:22:14 -0800 Subject: [PATCH 10/40] docs: change examples to uuid --- docs/docs/integrations/postgres.md | 2 +- docs/docs/other/telemetry.md | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/docs/integrations/postgres.md b/docs/docs/integrations/postgres.md index 4168c280..aee5d09c 100644 --- a/docs/docs/integrations/postgres.md +++ b/docs/docs/integrations/postgres.md @@ -73,7 +73,7 @@ table formatter: https://codebeautify.org/markdown-formatter | timestamptz | [date_time](../content/date-time) | | timestamp | [naive_date_time](../content/date-time) | | date | [naive_date](../content/date-time) | -| uuid | [string](../content/string#uuid) | +| uuid | [uuid](../content/uuid) | ### Example Import diff --git a/docs/docs/other/telemetry.md b/docs/docs/other/telemetry.md index 23dd401c..98e52a34 100644 --- a/docs/docs/other/telemetry.md +++ b/docs/docs/other/telemetry.md @@ -79,8 +79,7 @@ activity: { "type": "object", "distinct_id": { - "type": "string", - "uuid": {} + "type": "uuid", }, "command": { "type": "string", From 5b3cf2c39ebc43834b73d67012945a8d01830fdd Mon Sep 17 00:00:00 2001 From: iamwacko Date: Sat, 21 Jan 2023 12:27:58 -0800 Subject: [PATCH 11/40] docs: fix trailing comma --- docs/docs/other/telemetry.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/other/telemetry.md b/docs/docs/other/telemetry.md index 98e52a34..727f092c 100644 --- a/docs/docs/other/telemetry.md +++ b/docs/docs/other/telemetry.md @@ -79,7 +79,7 @@ activity: { "type": "object", "distinct_id": { - "type": "uuid", + "type": "uuid" }, "command": { "type": "string", From 4c20e04af4b4cc506174134ce915774209aaf048 Mon Sep 17 00:00:00 2001 From: iamwacko Date: Sat, 21 Jan 2023 12:34:45 -0800 Subject: [PATCH 12/40] docs: more uuid doc stuff --- docs/docs/content/string.md | 14 -------------- docs/docs/content/uuid.md | 2 +- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/docs/docs/content/string.md b/docs/docs/content/string.md index 7e2d8523..c80527ec 100644 --- a/docs/docs/content/string.md +++ b/docs/docs/content/string.md @@ -15,20 +15,6 @@ String values generated by a specified regular expression in the `pattern` key. } ``` -## uuid - -`uuid` generates hyphenated [UUIDs](https://en.wikipedia.org/wiki/Universally_unique_identifier). - -This generator has no parameters. - -#### Example - -```json synth -{ - "type": "uuid", -} -``` - ## format `format` allows to format one or more string values by parsing a parametric diff --git a/docs/docs/content/uuid.md b/docs/docs/content/uuid.md index 79c758f6..69b87f6f 100644 --- a/docs/docs/content/uuid.md +++ b/docs/docs/content/uuid.md @@ -8,6 +8,6 @@ This generator has no parameters. ```json synth { - "type": "uuid", + "type": "uuid" } ``` From 167434bd3387384625c6f3e5a1751f5393d430e3 Mon Sep 17 00:00:00 2001 From: iamwacko Date: Sat, 21 Jan 2023 12:49:04 -0800 Subject: [PATCH 13/40] docs: more docs things --- docs/blog/2021-08-31-seeding-databases-tutorial.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/blog/2021-08-31-seeding-databases-tutorial.md b/docs/blog/2021-08-31-seeding-databases-tutorial.md index 8bf665f9..48be7ea2 100644 --- a/docs/blog/2021-08-31-seeding-databases-tutorial.md +++ b/docs/blog/2021-08-31-seeding-databases-tutorial.md @@ -550,7 +550,6 @@ identified by the presence of a distinguishing field which can be - `"faker"` - `"pattern"` -- `"uuid"` - [and a lot more][synth-string]... Since we are interested in generating email addresses, we will be using @@ -884,4 +883,4 @@ community would be happy to help if you encounter an issue! [npm-script]: https://github.com/brokad/synth/tree/master/examples/message_board/helpers/db.js -[prisma-relation-mongo]: https://www.prisma.io/docs/concepts/components/prisma-schema/relations/one-to-many-relations \ No newline at end of file +[prisma-relation-mongo]: https://www.prisma.io/docs/concepts/components/prisma-schema/relations/one-to-many-relations From f56d0102a1f9eb31b4f60da5d4c07253811b3adc Mon Sep 17 00:00:00 2001 From: iamwacko Date: Sat, 21 Jan 2023 12:59:09 -0800 Subject: [PATCH 14/40] fix: change tests to work with new uuid --- core/src/schema/content/mod.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/core/src/schema/content/mod.rs b/core/src/schema/content/mod.rs index 02b4c809..2284fff4 100644 --- a/core/src/schema/content/mod.rs +++ b/core/src/schema/content/mod.rs @@ -711,8 +711,7 @@ pub mod tests { "type": "object", "skip_when_null": true, "_uuid": { - "type": "string", - "uuid": {}, + "type": "uuid", "hidden": true }, "user_id": { @@ -907,7 +906,7 @@ pub mod tests { #[test] #[should_panic( - expected = "`string` generator is missing a subtype. Try adding `pattern`, `faker`, `categorical`, `serialized`, `uuid`, `truncated`, or `format`" + expected = "`string` generator is missing a subtype. Try adding `pattern`, `faker`, `categorical`, `serialized`, `truncated`, or `format`" )] fn string_missing_subtype() { let _schema: Content = schema!({ From f385694adf03abd6951433aefef3dad0478b62e1 Mon Sep 17 00:00:00 2001 From: iamwacko Date: Sat, 21 Jan 2023 13:12:54 -0800 Subject: [PATCH 15/40] fix: change error message for string subtypes --- core/src/schema/content/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/schema/content/mod.rs b/core/src/schema/content/mod.rs index 2284fff4..d0978f8d 100644 --- a/core/src/schema/content/mod.rs +++ b/core/src/schema/content/mod.rs @@ -311,7 +311,7 @@ content! { Uuid(UuidContent) => None, Bool(BoolContent) => "missing a subtype. Try adding `constant`, or `frequency`", Number(NumberContent) => "missing a subtype. Try adding `constant`, `range`, or `id`", - String(StringContent) => "missing a subtype. Try adding `pattern`, `faker`, `categorical`, `serialized`, `uuid`, `truncated`, or `format`", + String(StringContent) => "missing a subtype. Try adding `pattern`, `faker`, `categorical`, `serialized`, `truncated`, or `format`", DateTime(DateTimeContent) => "missing a `format` field", Array(ArrayContent) => "missing a `length` and `content` field", Object(ObjectContent) => None, From fbf75cb31539ff8068f53e01fea561a3e5878676 Mon Sep 17 00:00:00 2001 From: iamwacko Date: Sat, 21 Jan 2023 13:18:30 -0800 Subject: [PATCH 16/40] fix: tests changed --- .../errors/generate/192-string-missing-subtype/errors.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synth/testing_harness/errors/generate/192-string-missing-subtype/errors.txt b/synth/testing_harness/errors/generate/192-string-missing-subtype/errors.txt index ea695d81..dbc4aa43 100644 --- a/synth/testing_harness/errors/generate/192-string-missing-subtype/errors.txt +++ b/synth/testing_harness/errors/generate/192-string-missing-subtype/errors.txt @@ -3,4 +3,4 @@ Error: Unable to open the namespace "generate/192-string-missing-subtype" Caused by: 0: at file generate/192-string-missing-subtype/schema.json 1: Failed to parse collection - 2: `string` generator is missing a subtype. Try adding `pattern`, `faker`, `categorical`, `serialized`, `uuid`, `truncated`, or `format` at line 10 column 1 + 2: `string` generator is missing a subtype. Try adding `pattern`, `faker`, `categorical`, `serialized`, `truncated`, or `format` at line 10 column 1 From 2704c933d30c6736f3dd5d3d39b5f23a4fc60995 Mon Sep 17 00:00:00 2001 From: iamwacko Date: Sat, 21 Jan 2023 13:28:02 -0800 Subject: [PATCH 17/40] fix: change schema for tests --- core/src/schema/content/mod.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/src/schema/content/mod.rs b/core/src/schema/content/mod.rs index d0978f8d..ce5b7423 100644 --- a/core/src/schema/content/mod.rs +++ b/core/src/schema/content/mod.rs @@ -711,8 +711,7 @@ pub mod tests { "type": "object", "skip_when_null": true, "_uuid": { - "type": "uuid", - "hidden": true + "type": "uuid" }, "user_id": { "type": "number", From 599f43458dc08fd2cdd57f055eb8da270e030fab Mon Sep 17 00:00:00 2001 From: iamwacko Date: Sat, 21 Jan 2023 13:44:44 -0800 Subject: [PATCH 18/40] fix: hidden:true --- core/src/schema/content/mod.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/src/schema/content/mod.rs b/core/src/schema/content/mod.rs index ce5b7423..a82a788c 100644 --- a/core/src/schema/content/mod.rs +++ b/core/src/schema/content/mod.rs @@ -710,8 +710,9 @@ pub mod tests { pub static ref USER_SCHEMA: Content = schema!({ "type": "object", "skip_when_null": true, - "_uuid": { - "type": "uuid" + "unecessary_uuid": { + "type": "uuid", + "hidden": true }, "user_id": { "type": "number", From be6ecc2d8cb74294b5bd076210a581325793ad6a Mon Sep 17 00:00:00 2001 From: iamwacko Date: Sat, 21 Jan 2023 14:14:33 -0800 Subject: [PATCH 19/40] fix: test, maybe --- core/src/schema/content/mod.rs | 2 +- core/src/schema/content/uuid.rs | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/core/src/schema/content/mod.rs b/core/src/schema/content/mod.rs index a82a788c..d0978f8d 100644 --- a/core/src/schema/content/mod.rs +++ b/core/src/schema/content/mod.rs @@ -710,7 +710,7 @@ pub mod tests { pub static ref USER_SCHEMA: Content = schema!({ "type": "object", "skip_when_null": true, - "unecessary_uuid": { + "_uuid": { "type": "uuid", "hidden": true }, diff --git a/core/src/schema/content/uuid.rs b/core/src/schema/content/uuid.rs index a2721d0f..51e5ed90 100644 --- a/core/src/schema/content/uuid.rs +++ b/core/src/schema/content/uuid.rs @@ -1,7 +1,5 @@ use super::prelude::*; -use serde::{Deserialize, Serialize}; - #[derive(Default, Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)] #[serde(rename_all = "snake_case")] #[serde(deny_unknown_fields)] From 5cbdbc99bb6c1e61df55a37bdaac1b48bc1702b9 Mon Sep 17 00:00:00 2001 From: iamwacko Date: Sat, 21 Jan 2023 17:21:44 -0800 Subject: [PATCH 20/40] test: added uuid to tests --- core/src/compile/mod.rs | 9 +++++++++ core/src/graph/mod.rs | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/core/src/compile/mod.rs b/core/src/compile/mod.rs index cd6a8643..86cc9081 100644 --- a/core/src/compile/mod.rs +++ b/core/src/compile/mod.rs @@ -346,6 +346,15 @@ pub mod tests { assert!(complete(generator).unwrap().as_bool().unwrap()) } + #[test] + fn compile_uuid() { + let generator = generator! ({ + "type": "uuid" + }); + let value = complete(generator).unwrap(); + assert!(value.is_uuid()) + } + #[test] fn compile_linear() { let generator = generator!({ diff --git a/core/src/graph/mod.rs b/core/src/graph/mod.rs index 5d6fa125..b9199eb0 100644 --- a/core/src/graph/mod.rs +++ b/core/src/graph/mod.rs @@ -633,6 +633,10 @@ impl Value { self.as_object().is_some() } + pub fn is_uuid(&self) -> bool { + self.as_uuid().is_some() + } + pub fn is_array(&self) -> bool { self.as_array().is_some() } @@ -679,6 +683,13 @@ impl Value { } } + pub fn as_uuid(&self) -> Option<&Uuid> { + match *self { + Value::Uuid(ref u) => Some(u), + _ => None, + } + } + pub fn as_array(&self) -> Option<&Vec> { match *self { Value::Array(ref vec) => Some(vec), @@ -724,6 +735,13 @@ impl Value { } } + pub fn as_uuid(&mut self) -> Option<&mut Uuid> { + match *self { + Value::Uuid(ref mut u) => Some(u), + _ => None, + } + } + pub fn as_array_mut(&mut self) -> Option<&mut Vec> { match *self { Value::Array(ref mut vec) => Some(vec), From 3432858442c59f8cd8cd5ac81b218b726feaf5e9 Mon Sep 17 00:00:00 2001 From: iamwacko Date: Sat, 21 Jan 2023 17:26:06 -0800 Subject: [PATCH 21/40] fix: typo in code --- core/src/graph/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/graph/mod.rs b/core/src/graph/mod.rs index b9199eb0..d8b429e8 100644 --- a/core/src/graph/mod.rs +++ b/core/src/graph/mod.rs @@ -735,7 +735,7 @@ impl Value { } } - pub fn as_uuid(&mut self) -> Option<&mut Uuid> { + pub fn as_uuid_mut(&mut self) -> Option<&mut Uuid> { match *self { Value::Uuid(ref mut u) => Some(u), _ => None, From 28ee34669be37d216e1697b0f08322863d4f8f46 Mon Sep 17 00:00:00 2001 From: iamwacko Date: Sat, 21 Jan 2023 19:16:29 -0800 Subject: [PATCH 22/40] fix: hopefully --- core/src/graph/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/graph/mod.rs b/core/src/graph/mod.rs index d8b429e8..7f736b76 100644 --- a/core/src/graph/mod.rs +++ b/core/src/graph/mod.rs @@ -322,6 +322,7 @@ impl TryFrom for String { Value::String(str) => Ok(str), Value::Number(num) => Ok(num.to_string()), Value::DateTime(date) => Ok(date.format_to_string()), + Value::Uuid(u) => Ok(u.hyphenated().to_string()), otherwise => Err(failed_crate!( target: Release, "invalid type: expected 'String', found '{}'", From 80202f73dee805a2add55a964832dce13453b524 Mon Sep 17 00:00:00 2001 From: iamwacko Date: Thu, 9 Feb 2023 18:48:54 -0800 Subject: [PATCH 23/40] fix: debug errors --- core/src/graph/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/graph/mod.rs b/core/src/graph/mod.rs index 7f736b76..14239802 100644 --- a/core/src/graph/mod.rs +++ b/core/src/graph/mod.rs @@ -1201,6 +1201,7 @@ pub mod tests { let mut model = Graph::from_namespace(&USER_NAMESPACE).unwrap().aggregate(); let mut rng = rand::thread_rng(); let ser = OwnedSerializable::new(model.try_next_yielded(&mut rng).unwrap()); + dbg!(ser.clone()); serde_json::to_string_pretty(&ser).unwrap(); } From 96563bffe2273f62bbdf3c1bacacefb156e67328 Mon Sep 17 00:00:00 2001 From: iamwacko Date: Thu, 9 Feb 2023 19:03:11 -0800 Subject: [PATCH 24/40] chore: added more annotations to help with debugging --- gen/src/ser.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gen/src/ser.rs b/gen/src/ser.rs index 3957da40..e340aaf4 100644 --- a/gen/src/ser.rs +++ b/gen/src/ser.rs @@ -13,6 +13,7 @@ use serde::ser::{SerializeMap, SerializeSeq, SerializeStruct}; use std::cell::RefCell; use std::iter::Peekable; +#[derive(Clone)] struct Hidden(RefCell>); impl Hidden @@ -51,6 +52,7 @@ where /// A wrapper around an iterator of [`Token`](crate::value::Token)s /// that implement [`Serialize`](serde::Serialize). +#[derive(Clone)] pub struct OwnedSerializable { inner: Hidden, } From e99f90c15461e16d0d1f34c261cd6b5c370f2558 Mon Sep 17 00:00:00 2001 From: iamwacko Date: Thu, 9 Feb 2023 19:23:11 -0800 Subject: [PATCH 25/40] fix: Clone not implemented --- core/src/graph/mod.rs | 2 +- gen/src/ser.rs | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/core/src/graph/mod.rs b/core/src/graph/mod.rs index 14239802..54c4834f 100644 --- a/core/src/graph/mod.rs +++ b/core/src/graph/mod.rs @@ -1201,7 +1201,7 @@ pub mod tests { let mut model = Graph::from_namespace(&USER_NAMESPACE).unwrap().aggregate(); let mut rng = rand::thread_rng(); let ser = OwnedSerializable::new(model.try_next_yielded(&mut rng).unwrap()); - dbg!(ser.clone()); + dbg!(ser); serde_json::to_string_pretty(&ser).unwrap(); } diff --git a/gen/src/ser.rs b/gen/src/ser.rs index e340aaf4..3957da40 100644 --- a/gen/src/ser.rs +++ b/gen/src/ser.rs @@ -13,7 +13,6 @@ use serde::ser::{SerializeMap, SerializeSeq, SerializeStruct}; use std::cell::RefCell; use std::iter::Peekable; -#[derive(Clone)] struct Hidden(RefCell>); impl Hidden @@ -52,7 +51,6 @@ where /// A wrapper around an iterator of [`Token`](crate::value::Token)s /// that implement [`Serialize`](serde::Serialize). -#[derive(Clone)] pub struct OwnedSerializable { inner: Hidden, } From 8f699fae7c375d41a62578e58999ea4344df3745 Mon Sep 17 00:00:00 2001 From: iamwacko Date: Thu, 9 Feb 2023 19:28:58 -0800 Subject: [PATCH 26/40] chore: derive debug --- gen/src/ser.rs | 2 ++ gen/src/value.rs | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/gen/src/ser.rs b/gen/src/ser.rs index 3957da40..8e23fe77 100644 --- a/gen/src/ser.rs +++ b/gen/src/ser.rs @@ -13,6 +13,7 @@ use serde::ser::{SerializeMap, SerializeSeq, SerializeStruct}; use std::cell::RefCell; use std::iter::Peekable; +#[derive(Debug)] struct Hidden(RefCell>); impl Hidden @@ -51,6 +52,7 @@ where /// A wrapper around an iterator of [`Token`](crate::value::Token)s /// that implement [`Serialize`](serde::Serialize). +#[derive(Debug)] pub struct OwnedSerializable { inner: Hidden, } diff --git a/gen/src/value.rs b/gen/src/value.rs index 8ee52f1b..dceea2c7 100644 --- a/gen/src/value.rs +++ b/gen/src/value.rs @@ -352,7 +352,7 @@ generate_special_enum!( generate_enum!( /// A custom tokenization for the serde data model. - #[derive(Clone, PartialEq, Eq, Hash)] + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum Token { /// A token encoding serde primitive types. Primitive(Primitive), From dd55cae66cefc9abffc1417f5e7eb18df71d590c Mon Sep 17 00:00:00 2001 From: iamwacko Date: Thu, 9 Feb 2023 19:34:31 -0800 Subject: [PATCH 27/40] fix: conflicting implementations --- gen/src/value.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gen/src/value.rs b/gen/src/value.rs index dceea2c7..8ee52f1b 100644 --- a/gen/src/value.rs +++ b/gen/src/value.rs @@ -352,7 +352,7 @@ generate_special_enum!( generate_enum!( /// A custom tokenization for the serde data model. - #[derive(Debug, Clone, PartialEq, Eq, Hash)] + #[derive(Clone, PartialEq, Eq, Hash)] pub enum Token { /// A token encoding serde primitive types. Primitive(Primitive), From b7eef8e5a9b75d4a9edf34f4bd5b089c6d1372e7 Mon Sep 17 00:00:00 2001 From: iamwacko Date: Thu, 9 Feb 2023 19:46:30 -0800 Subject: [PATCH 28/40] chore: add debug to generic trait bound --- gen/src/ser.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gen/src/ser.rs b/gen/src/ser.rs index 8e23fe77..cc0d9e71 100644 --- a/gen/src/ser.rs +++ b/gen/src/ser.rs @@ -14,7 +14,7 @@ use std::cell::RefCell; use std::iter::Peekable; #[derive(Debug)] -struct Hidden(RefCell>); +struct Hidden(RefCell>); impl Hidden where From 4a98de974b2b28fbd280fd24612add852b86de21 Mon Sep 17 00:00:00 2001 From: iamwacko Date: Thu, 9 Feb 2023 19:51:54 -0800 Subject: [PATCH 29/40] chore: revert new trait bound --- gen/src/ser.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gen/src/ser.rs b/gen/src/ser.rs index cc0d9e71..8e23fe77 100644 --- a/gen/src/ser.rs +++ b/gen/src/ser.rs @@ -14,7 +14,7 @@ use std::cell::RefCell; use std::iter::Peekable; #[derive(Debug)] -struct Hidden(RefCell>); +struct Hidden(RefCell>); impl Hidden where From fc75bf7650cbf0fac78be6801ec3f36b5679ebdf Mon Sep 17 00:00:00 2001 From: iamwacko Date: Thu, 9 Feb 2023 20:02:58 -0800 Subject: [PATCH 30/40] chore: associated type trait bound --- gen/src/ser.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gen/src/ser.rs b/gen/src/ser.rs index 8e23fe77..33a3f5f2 100644 --- a/gen/src/ser.rs +++ b/gen/src/ser.rs @@ -14,7 +14,7 @@ use std::cell::RefCell; use std::iter::Peekable; #[derive(Debug)] -struct Hidden(RefCell>); +struct Hidden>(RefCell>); impl Hidden where From 387bff76abab644432d8ecaa04e72fd37d909245 Mon Sep 17 00:00:00 2001 From: iamwacko Date: Thu, 9 Feb 2023 20:09:13 -0800 Subject: [PATCH 31/40] chore: change to move to not use impl trait --- gen/src/ser.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gen/src/ser.rs b/gen/src/ser.rs index 33a3f5f2..9fa95779 100644 --- a/gen/src/ser.rs +++ b/gen/src/ser.rs @@ -14,7 +14,7 @@ use std::cell::RefCell; use std::iter::Peekable; #[derive(Debug)] -struct Hidden>(RefCell>); +struct Hidden, T: std::fmt::Debug>(RefCell>); impl Hidden where From 8dfaff53076d067921d25de68b742b1d0bc1a309 Mon Sep 17 00:00:00 2001 From: iamwacko Date: Thu, 9 Feb 2023 20:46:27 -0800 Subject: [PATCH 32/40] chore: make things work --- gen/src/ser.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gen/src/ser.rs b/gen/src/ser.rs index 9fa95779..8e23fe77 100644 --- a/gen/src/ser.rs +++ b/gen/src/ser.rs @@ -14,7 +14,7 @@ use std::cell::RefCell; use std::iter::Peekable; #[derive(Debug)] -struct Hidden, T: std::fmt::Debug>(RefCell>); +struct Hidden(RefCell>); impl Hidden where From 7a2b278a149da75a15346388be81edfadb16c8b7 Mon Sep 17 00:00:00 2001 From: iamwacko Date: Thu, 9 Feb 2023 21:03:25 -0800 Subject: [PATCH 33/40] chore: does where work for struct definitions --- gen/src/ser.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gen/src/ser.rs b/gen/src/ser.rs index 8e23fe77..31df63f6 100644 --- a/gen/src/ser.rs +++ b/gen/src/ser.rs @@ -14,7 +14,9 @@ use std::cell::RefCell; use std::iter::Peekable; #[derive(Debug)] -struct Hidden(RefCell>); +struct Hidden +where + I::Item: std::fmt::Debug(RefCell>); impl Hidden where From 45f3f37a471646fd2e41d91dd25b884b204bc82d Mon Sep 17 00:00:00 2001 From: iamwacko Date: Thu, 9 Feb 2023 21:08:46 -0800 Subject: [PATCH 34/40] chore: added comma --- gen/src/ser.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gen/src/ser.rs b/gen/src/ser.rs index 31df63f6..39b948d7 100644 --- a/gen/src/ser.rs +++ b/gen/src/ser.rs @@ -16,7 +16,8 @@ use std::iter::Peekable; #[derive(Debug)] struct Hidden where - I::Item: std::fmt::Debug(RefCell>); + I::Item: std::fmt::Debug, +(RefCell>); impl Hidden where From 98db275f816c38f574b1b1d01497e95025f29111 Mon Sep 17 00:00:00 2001 From: iamwacko Date: Thu, 9 Feb 2023 21:10:13 -0800 Subject: [PATCH 35/40] chore: changed location of where --- gen/src/ser.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/gen/src/ser.rs b/gen/src/ser.rs index 39b948d7..dd6f398a 100644 --- a/gen/src/ser.rs +++ b/gen/src/ser.rs @@ -14,10 +14,9 @@ use std::cell::RefCell; use std::iter::Peekable; #[derive(Debug)] -struct Hidden +struct Hidden(RefCell>) where - I::Item: std::fmt::Debug, -(RefCell>); + I::Item: std::fmt::Debug; impl Hidden where From 62036a7ca893298e321801ee20adade30b1afaec Mon Sep 17 00:00:00 2001 From: iamwacko Date: Thu, 9 Feb 2023 21:15:22 -0800 Subject: [PATCH 36/40] chore: removed Debug notation --- core/src/graph/mod.rs | 1 - gen/src/ser.rs | 4 ---- 2 files changed, 5 deletions(-) diff --git a/core/src/graph/mod.rs b/core/src/graph/mod.rs index 54c4834f..7f736b76 100644 --- a/core/src/graph/mod.rs +++ b/core/src/graph/mod.rs @@ -1201,7 +1201,6 @@ pub mod tests { let mut model = Graph::from_namespace(&USER_NAMESPACE).unwrap().aggregate(); let mut rng = rand::thread_rng(); let ser = OwnedSerializable::new(model.try_next_yielded(&mut rng).unwrap()); - dbg!(ser); serde_json::to_string_pretty(&ser).unwrap(); } diff --git a/gen/src/ser.rs b/gen/src/ser.rs index dd6f398a..cc8f36aa 100644 --- a/gen/src/ser.rs +++ b/gen/src/ser.rs @@ -13,10 +13,7 @@ use serde::ser::{SerializeMap, SerializeSeq, SerializeStruct}; use std::cell::RefCell; use std::iter::Peekable; -#[derive(Debug)] struct Hidden(RefCell>) -where - I::Item: std::fmt::Debug; impl Hidden where @@ -54,7 +51,6 @@ where /// A wrapper around an iterator of [`Token`](crate::value::Token)s /// that implement [`Serialize`](serde::Serialize). -#[derive(Debug)] pub struct OwnedSerializable { inner: Hidden, } From fcb5b517bdaf22d088a087d869381671c31e8318 Mon Sep 17 00:00:00 2001 From: iamwacko Date: Thu, 9 Feb 2023 21:15:44 -0800 Subject: [PATCH 37/40] chore: removed Debug notation --- gen/src/ser.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gen/src/ser.rs b/gen/src/ser.rs index cc8f36aa..3957da40 100644 --- a/gen/src/ser.rs +++ b/gen/src/ser.rs @@ -13,7 +13,7 @@ use serde::ser::{SerializeMap, SerializeSeq, SerializeStruct}; use std::cell::RefCell; use std::iter::Peekable; -struct Hidden(RefCell>) +struct Hidden(RefCell>); impl Hidden where From 6f614eb007514deecf24614e8a3e99b23e952736 Mon Sep 17 00:00:00 2001 From: iamwacko Date: Tue, 18 Apr 2023 22:31:20 -0700 Subject: [PATCH 38/40] chore: update deps to fix compiles --- synth/Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/synth/Cargo.toml b/synth/Cargo.toml index 68609e31..38342190 100644 --- a/synth/Cargo.toml +++ b/synth/Cargo.toml @@ -46,7 +46,7 @@ log = "0.4.11" env_logger = "0.7.1" num_cpus = "1.0" -sysinfo = "0.15.2" +sysinfo = "0.28.4" strsim = "0.10.0" async-std = { version = "1.6.4", features = [ "attributes", "unstable" ] } @@ -67,7 +67,7 @@ rust_decimal = "1.10.3" indicatif = "0.15.0" dirs = "3.0.2" -mongodb = {version = "2.0.0-beta.3", features = ["sync", "bson-chrono-0_4"] , default-features = false} +mongodb = {version = "2.4.0", features = ["sync", "bson-chrono-0_4"] , default-features = false} sqlx = { version = "0.6", features = ["postgres", "mysql", "runtime-async-std-rustls", "decimal", "chrono"] } From 708fe809ff6458a42fc892161f175bfcfdf56701 Mon Sep 17 00:00:00 2001 From: iamwacko Date: Wed, 19 Apr 2023 21:50:21 -0700 Subject: [PATCH 39/40] chore: more work on uuid support --- Cargo.lock | 26 +++++++------------------- core/src/graph/uuid.rs | 25 +++++++++++++++++++++---- core/src/schema/content/uuid.rs | 5 +++-- 3 files changed, 31 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5755de74..e4b3355c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2151,10 +2151,8 @@ dependencies = [ "trust-dns-proto", "trust-dns-resolver", "typed-builder", - "uuid 0.8.2", - "version_check", - "webpki 0.21.4", - "webpki-roots 0.21.1", + "uuid 1.3.0", + "webpki-roots", ] [[package]] @@ -3353,8 +3351,8 @@ dependencies = [ "stringprep", "thiserror", "url", - "uuid 1.2.2", - "webpki-roots 0.22.5", + "uuid 1.3.0", + "webpki-roots", "whoami", ] @@ -3597,7 +3595,7 @@ dependencies = [ "synth-gen", "tempfile", "uriparse", - "uuid 1.2.2", + "uuid 1.3.0", ] [[package]] @@ -3630,9 +3628,9 @@ dependencies = [ [[package]] name = "sysinfo" -version = "0.28.2" +version = "0.28.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e847e2de7a137c8c2cede5095872dbb00f4f9bf34d061347e36b43322acd56" +checksum = "b4c2f3ca6693feb29a89724516f016488e9aafc7f37264f898593ee4b942f31b" dependencies = [ "cfg-if 1.0.0", "core-foundation-sys", @@ -4110,16 +4108,6 @@ dependencies = [ "serde", ] -[[package]] -name = "uuid" -version = "1.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "422ee0de9031b5b948b97a8fc04e3aa35230001a722ddd27943e0be31564ce4c" -dependencies = [ - "getrandom 0.2.3", - "serde", -] - [[package]] name = "value-bag" version = "1.0.0-alpha.9" diff --git a/core/src/graph/uuid.rs b/core/src/graph/uuid.rs index d43c0615..3590103a 100644 --- a/core/src/graph/uuid.rs +++ b/core/src/graph/uuid.rs @@ -1,13 +1,30 @@ use super::prelude::*; use uuid::Uuid; -pub struct UuidNode(); +derive_generator! { + yield Token, + return Result, + pub struct UuidNode(Valuize, Uuid>); +} + +impl From for UuidNode { + fn from(value: RandomUuid) -> Self { + Self( + value + .into_token() + .map_complete(value_from_ok::), + ) + } +} + +pub struct RandomUuid {} -impl Generator for UuidNode { +impl Generator for RandomUuid { type Yield = Token; - type Return = Result; + type Return = Result; fn next(&mut self, rng: &mut R) -> GeneratorState { - GeneratorState::Complete(Ok(Value::Uuid(Uuid::from_u128(rng.gen())))) + let uuid = Uuid::from_u128(rng.gen()); + GeneratorState::Complete(Ok(uuid)) } } diff --git a/core/src/schema/content/uuid.rs b/core/src/schema/content/uuid.rs index 51e5ed90..0609b499 100644 --- a/core/src/schema/content/uuid.rs +++ b/core/src/schema/content/uuid.rs @@ -1,4 +1,5 @@ use super::prelude::*; +use crate::graph::uuid::RandomUuid; #[derive(Default, Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)] #[serde(rename_all = "snake_case")] @@ -7,7 +8,7 @@ pub struct UuidContent {} impl Compile for UuidContent { fn compile<'a, C: Compiler<'a>>(&'a self, mut _compiler: C) -> Result { - let node = UuidNode(); - Ok(Graph::Uuid(node)) + let random_uuid = RandomUuid{ }; + Ok(Graph::Uuid(random_uuid.into())) } } From 2c088a3f8affae52e309febf44a47991f05ead7b Mon Sep 17 00:00:00 2001 From: iamwacko Date: Wed, 19 Apr 2023 21:52:11 -0700 Subject: [PATCH 40/40] chore: cargo fmt --- core/src/graph/uuid.rs | 8 ++------ core/src/schema/content/uuid.rs | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/core/src/graph/uuid.rs b/core/src/graph/uuid.rs index 3590103a..1dfcf06e 100644 --- a/core/src/graph/uuid.rs +++ b/core/src/graph/uuid.rs @@ -9,12 +9,8 @@ derive_generator! { impl From for UuidNode { fn from(value: RandomUuid) -> Self { - Self( - value - .into_token() - .map_complete(value_from_ok::), - ) - } + Self(value.into_token().map_complete(value_from_ok::)) + } } pub struct RandomUuid {} diff --git a/core/src/schema/content/uuid.rs b/core/src/schema/content/uuid.rs index 0609b499..057f9cbb 100644 --- a/core/src/schema/content/uuid.rs +++ b/core/src/schema/content/uuid.rs @@ -8,7 +8,7 @@ pub struct UuidContent {} impl Compile for UuidContent { fn compile<'a, C: Compiler<'a>>(&'a self, mut _compiler: C) -> Result { - let random_uuid = RandomUuid{ }; + let random_uuid = RandomUuid {}; Ok(Graph::Uuid(random_uuid.into())) } }