Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,4 @@ shards/tests/.edits_backup

local/
.claude/
shards/rust_macro/Cargo.lock
2 changes: 0 additions & 2 deletions deps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -312,5 +312,3 @@ add_subdirectory(opus)

add_library(crdt_lite INTERFACE)
target_include_directories(crdt_lite INTERFACE crdt-lite)

add_subdirectory(FTXUI)
266 changes: 42 additions & 224 deletions shards/modules/core/src/uuid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,20 @@ use shards::core::register_legacy_shard;
use shards::core::register_shard;
use shards::shard::LegacyShard;
use shards::shard::Shard;
use shards::simple_shard;

use shards::types::BytesOut;
use shards::types::ClonedVar;
use shards::types::Context;
use shards::types::ExposedTypes;
use shards::types::InstanceData;
use shards::types::OptionalString;
use shards::types::BOOL_TYPES_SLICE;
use shards::types::StringOut;
use shards::types::BYTES_OR_STRING_TYPES;
use shards::types::BYTES_TYPES;
use shards::types::INT16_TYPES;
use shards::types::INT_TYPES;
use shards::types::INT_TYPES_SLICE;
use shards::types::NONE_TYPES;

use shards::types::Parameters;

use shards::types::Type;

use shards::types::STRING_TYPES;

use shards::types::common_type;
use shards::types::Types;
use shards::types::Var;
Expand All @@ -33,40 +27,45 @@ use core::convert::TryInto;
use std::str::FromStr;
use std::sync::RwLock;

#[derive(Default)]
struct UUIDCreate {}

impl LegacyShard for UUIDCreate {
fn registerName() -> &'static str {
cstr!("UUID")
}

fn hash() -> u32 {
compile_time_crc32::crc32!("UUID-rust-0x20250822")
}
// Simple shards using the new macro

fn name(&mut self) -> &str {
"UUID"
}

fn help(&mut self) -> OptionalString {
OptionalString(shccstr!("Outputs a UUID (Universally Unique Identifier)."))
}
#[simple_shard("UUID", "Outputs a UUID (Universally Unique Identifier).")]
fn uuid_create(_: ()) -> [u8; 16] {
let uuid = uuid::Uuid::new_v4();
*uuid.as_bytes()
}

fn inputTypes(&mut self) -> &std::vec::Vec<Type> {
&NONE_TYPES
#[simple_shard("UUID.ToString", "Reads a UUID and formats it into a readable string.")]
fn uuid_to_string(
input: [u8; 16],
#[param("Hyphenated", "Whether to use hyphens in the output.", default = false)]
hyphenated: bool,
) -> StringOut {
let uuid = uuid::Uuid::from_bytes(input);
if hyphenated {
uuid.hyphenated().to_string().as_str().into()
} else {
uuid.simple().to_string().as_str().into()
}
}

fn outputTypes(&mut self) -> &std::vec::Vec<Type> {
&INT16_TYPES
}
#[simple_shard("UUID.ToBytes", "Reads a UUID and formats it into bytes.")]
fn uuid_to_bytes(input: [u8; 16]) -> BytesOut {
input.as_slice().into()
}

fn activate(&mut self, _: &Context, _: &Var) -> Result<Option<Var>, &str> {
let uuid = uuid::Uuid::new_v4();
Ok(Some(uuid.as_bytes().into()))
}
#[simple_shard("NanoID", "Creates a random NanoID.")]
fn nanoid_create(
_: (),
#[param("Size", "The output string length of the created NanoID.", default = 21i64)]
size: i64,
) -> StringOut {
let size = size as usize;
nanoid::nanoid!(size).as_str().into()
}

// Legacy shard for UUID.Convert (handles multiple input types)

#[derive(Default)]
struct UUIDConvert {}

Expand Down Expand Up @@ -94,7 +93,7 @@ impl LegacyShard for UUIDConvert {
}

fn outputTypes(&mut self) -> &std::vec::Vec<Type> {
&INT16_TYPES
&shards::types::INT16_TYPES
}

fn activate(&mut self, _: &Context, input: &Var) -> Result<Option<Var>, &str> {
Expand All @@ -113,188 +112,7 @@ impl LegacyShard for UUIDConvert {
}
}

lazy_static! {
static ref PARAMETERS: Parameters = vec![(
cstr!("Hyphenated"),
shccstr!("Whether to use hyphens in the output."),
BOOL_TYPES_SLICE
)
.into(),];
}

#[derive(Default)]
struct UUIDToString {
output: ClonedVar,
hyphenated: bool,
}

impl LegacyShard for UUIDToString {
fn registerName() -> &'static str {
cstr!("UUID.ToString")
}

fn hash() -> u32 {
compile_time_crc32::crc32!("UUID.ToString-rust-0x20250822")
}

fn name(&mut self) -> &str {
"UUID.ToString"
}

fn help(&mut self) -> OptionalString {
OptionalString(shccstr!(
"Reads an UUID and formats it into a readable string."
))
}

fn inputTypes(&mut self) -> &std::vec::Vec<Type> {
&INT16_TYPES
}

fn outputTypes(&mut self) -> &std::vec::Vec<Type> {
&STRING_TYPES
}

fn parameters(&mut self) -> Option<&Parameters> {
Some(&PARAMETERS)
}

fn setParam(&mut self, index: i32, value: &Var) -> Result<(), &str> {
match index {
0 => Ok(self.hyphenated = value.try_into()?),
_ => unreachable!(),
}
}

fn getParam(&mut self, index: i32) -> Var {
match index {
0 => self.hyphenated.into(),
_ => unreachable!(),
}
}

fn activate(&mut self, _: &Context, input: &Var) -> Result<Option<Var>, &str> {
let bytes: [u8; 16] = input.try_into()?;
let uuid = uuid::Uuid::from_bytes(bytes);
self.output = if self.hyphenated {
uuid.hyphenated().to_string().into()
} else {
uuid.simple().to_string().into()
};
Ok(Some(self.output.0))
}
}

#[derive(Default)]
struct UUIDToBytes {
output: ClonedVar,
}

impl LegacyShard for UUIDToBytes {
fn registerName() -> &'static str {
cstr!("UUID.ToBytes")
}

fn hash() -> u32 {
compile_time_crc32::crc32!("UUID.ToBytes-rust-0x20250822")
}

fn name(&mut self) -> &str {
"UUID.ToBytes"
}

fn help(&mut self) -> OptionalString {
OptionalString(shccstr!("Reads an UUID and formats it into bytes."))
}

fn inputTypes(&mut self) -> &std::vec::Vec<Type> {
&INT16_TYPES
}

fn outputTypes(&mut self) -> &std::vec::Vec<Type> {
&BYTES_TYPES
}

fn activate(&mut self, _: &Context, input: &Var) -> Result<Option<Var>, &str> {
let bytes: [u8; 16] = input.try_into()?;
self.output = bytes.as_ref().into();
Ok(Some(self.output.0))
}
}

lazy_static! {
static ref NANO_PARAMETERS: Parameters = vec![(
cstr!("Size"),
shccstr!("The output string length of the created NanoID."),
INT_TYPES_SLICE
)
.into(),];
}

struct NanoIDCreate {
size: i64,
output: ClonedVar,
}

impl Default for NanoIDCreate {
fn default() -> Self {
Self {
size: 21,
output: Default::default(),
}
}
}

impl LegacyShard for NanoIDCreate {
fn registerName() -> &'static str {
cstr!("NanoID")
}

fn hash() -> u32 {
compile_time_crc32::crc32!("NanoID-rust-0x20250822")
}

fn name(&mut self) -> &str {
"NanoID"
}

fn help(&mut self) -> OptionalString {
OptionalString(shccstr!("Creates a random NanoID."))
}

fn inputTypes(&mut self) -> &std::vec::Vec<Type> {
&NONE_TYPES
}

fn outputTypes(&mut self) -> &std::vec::Vec<Type> {
&STRING_TYPES
}

fn parameters(&mut self) -> Option<&Parameters> {
Some(&NANO_PARAMETERS)
}

fn setParam(&mut self, index: i32, value: &Var) -> Result<(), &str> {
match index {
0 => Ok(self.size = value.try_into()?),
_ => unreachable!(),
}
}

fn getParam(&mut self, index: i32) -> Var {
match index {
0 => self.size.into(),
_ => unreachable!(),
}
}

fn activate(&mut self, _: &Context, _: &Var) -> Result<Option<Var>, &str> {
let size = self.size as usize;
let id = nanoid::nanoid!(size);
self.output = id.into();
Ok(Some(self.output.0))
}
}
// Snowflake shard (uses global state and custom warmup validation)

lazy_static! {
static ref SNOWFLAKE_GENERATOR: RwLock<snowflake::SnowflakeIdGenerator> =
Expand Down Expand Up @@ -325,7 +143,7 @@ impl Default for SnowflakeShard {
#[shards::shard_impl]
impl Shard for SnowflakeShard {
fn input_types(&mut self) -> &Types {
&NONE_TYPES
&shards::types::NONE_TYPES
}

fn output_types(&mut self) -> &Types {
Expand Down Expand Up @@ -370,10 +188,10 @@ impl Shard for SnowflakeShard {
}

pub fn register_shards() {
register_legacy_shard::<UUIDCreate>();
register_legacy_shard::<UUIDToString>();
register_legacy_shard::<UUIDToBytes>();
register_legacy_shard::<NanoIDCreate>();
register_shard::<UUIDShard>();
register_shard::<UUIDToStringShard>();
register_shard::<UUIDToBytesShard>();
register_shard::<NanoIDShard>();
register_legacy_shard::<UUIDConvert>();
register_shard::<SnowflakeShard>();
}
Loading
Loading