lib

Core libraries for Radroots
git clone https://radroots.dev/git/lib.git
Log | Files | Refs | README

commit b789991c7292870652bef42d15d54172d29dd691
parent dffb7e0f1387d297ae6a41db0a807448308a9f20
Author: triesap <tyson@radroots.org>
Date:   Thu, 11 Jun 2026 14:09:03 -0700

refactor: align core bindings

Diffstat:
Mcrates/core_bindings/Cargo.toml | 1+
Mcrates/core_bindings/src/lib.rs | 117+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
Dcrates/core_bindings/src/typescript/types.ts | 25-------------------------
Mcrates/identity_bindings/Cargo.toml | 1+
Mcrates/identity_bindings/src/lib.rs | 23++++++++++++++++++-----
Dcrates/identity_bindings/src/typescript/constants.ts | 3---
6 files changed, 132 insertions(+), 38 deletions(-)

diff --git a/crates/core_bindings/Cargo.toml b/crates/core_bindings/Cargo.toml @@ -10,4 +10,5 @@ homepage.workspace = true publish = false [dependencies] +radroots_sdk_binding_model = { path = "../binding_model" } radroots_core = { workspace = true } diff --git a/crates/core_bindings/src/lib.rs b/crates/core_bindings/src/lib.rs @@ -1,15 +1,122 @@ pub use radroots_core as upstream; -pub const TYPES_TS: &str = include_str!("typescript/types.ts"); +use radroots_sdk_binding_model as ts; + +pub fn types_module() -> ts::TsModule { + ts::module(vec![ + ts::type_alias("RadrootsCoreCurrency", ts::string()), + ts::type_alias("RadrootsCoreDecimal", ts::string()), + ts::type_alias( + "RadrootsCoreDiscount", + ts::object(vec![ + ts::field("scope", ts::reference("RadrootsCoreDiscountScope")), + ts::field("threshold", ts::reference("RadrootsCoreDiscountThreshold")), + ts::field("value", ts::reference("RadrootsCoreDiscountValue")), + ]), + ), + ts::type_alias( + "RadrootsCoreDiscountScope", + ts::union(vec![ + ts::string_literal("bin"), + ts::string_literal("order_total"), + ]), + ), + ts::type_alias( + "RadrootsCoreDiscountThreshold", + ts::union(vec![ + ts::object(vec![ + ts::field("kind", ts::string_literal("bin_count")), + ts::field( + "amount", + ts::object(vec![ + ts::field("bin_id", ts::string()), + ts::field("min", ts::number()), + ]), + ), + ]), + ts::object(vec![ + ts::field("kind", ts::string_literal("order_quantity")), + ts::field( + "amount", + ts::object(vec![ts::field( + "min", + ts::reference("RadrootsCoreQuantity"), + )]), + ), + ]), + ]), + ), + ts::type_alias( + "RadrootsCoreDiscountValue", + ts::union(vec![ + ts::object(vec![ + ts::field("kind", ts::string_literal("money_per_bin")), + ts::field("amount", ts::reference("RadrootsCoreMoney")), + ]), + ts::object(vec![ + ts::field("kind", ts::string_literal("percent")), + ts::field("amount", ts::reference("RadrootsCorePercent")), + ]), + ]), + ), + ts::type_alias( + "RadrootsCoreMoney", + ts::object(vec![ + ts::field("amount", ts::string()), + ts::field("currency", ts::string()), + ]), + ), + ts::type_alias( + "RadrootsCorePercent", + ts::object(vec![ts::field("value", ts::string())]), + ), + ts::type_alias( + "RadrootsCoreQuantity", + ts::object(vec![ + ts::field("amount", ts::string()), + ts::field("unit", ts::reference("RadrootsCoreUnit")), + ts::field("label", ts::nullable(ts::string())), + ]), + ), + ts::type_alias( + "RadrootsCoreQuantityPrice", + ts::object(vec![ + ts::field("amount", ts::reference("RadrootsCoreMoney")), + ts::field("quantity", ts::reference("RadrootsCoreQuantity")), + ]), + ), + ts::type_alias( + "RadrootsCoreUnit", + ts::union(vec![ + ts::string_literal("each"), + ts::string_literal("kg"), + ts::string_literal("g"), + ts::string_literal("oz"), + ts::string_literal("lb"), + ts::string_literal("l"), + ts::string_literal("ml"), + ]), + ), + ts::type_alias( + "RadrootsCoreUnitDimension", + ts::union(vec![ + ts::string_literal("count"), + ts::string_literal("mass"), + ts::string_literal("volume"), + ]), + ), + ]) +} #[cfg(test)] mod tests { - use super::TYPES_TS; + use super::types_module; #[test] fn preserves_core_type_exports() { - assert!(TYPES_TS.contains("export type RadrootsCoreMoney")); - assert!(TYPES_TS.contains("export type RadrootsCoreQuantityPrice")); - assert!(TYPES_TS.contains("\"each\"")); + let rendered = types_module().render(); + assert!(rendered.contains("export type RadrootsCoreMoney")); + assert!(rendered.contains("export type RadrootsCoreQuantityPrice")); + assert!(rendered.contains("\"each\"")); } } diff --git a/crates/core_bindings/src/typescript/types.ts b/crates/core_bindings/src/typescript/types.ts @@ -1,25 +0,0 @@ -// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. - -export type RadrootsCoreCurrency = string; - -export type RadrootsCoreDecimal = string; - -export type RadrootsCoreDiscount = { scope: RadrootsCoreDiscountScope, threshold: RadrootsCoreDiscountThreshold, value: RadrootsCoreDiscountValue, }; - -export type RadrootsCoreDiscountScope = "bin" | "order_total"; - -export type RadrootsCoreDiscountThreshold = { "kind": "bin_count", "amount": { bin_id: string, min: number, } } | { "kind": "order_quantity", "amount": { min: RadrootsCoreQuantity, } }; - -export type RadrootsCoreDiscountValue = { "kind": "money_per_bin", "amount": RadrootsCoreMoney } | { "kind": "percent", "amount": RadrootsCorePercent }; - -export type RadrootsCoreMoney = { amount: string, currency: string, }; - -export type RadrootsCorePercent = { value: string, }; - -export type RadrootsCoreQuantity = { amount: string, unit: RadrootsCoreUnit, label: string | null, }; - -export type RadrootsCoreQuantityPrice = { amount: RadrootsCoreMoney, quantity: RadrootsCoreQuantity, }; - -export type RadrootsCoreUnit = "each" | "kg" | "g" | "oz" | "lb" | "l" | "ml"; - -export type RadrootsCoreUnitDimension = "count" | "mass" | "volume"; diff --git a/crates/identity_bindings/Cargo.toml b/crates/identity_bindings/Cargo.toml @@ -10,4 +10,5 @@ homepage.workspace = true publish = false [dependencies] +radroots_sdk_binding_model = { path = "../binding_model" } radroots_identity = { workspace = true } diff --git a/crates/identity_bindings/src/lib.rs b/crates/identity_bindings/src/lib.rs @@ -1,15 +1,28 @@ pub use radroots_identity as upstream; -pub const CONSTANTS_TS: &str = include_str!("typescript/constants.ts"); +use radroots_sdk_binding_model::{self as ts, TsValue}; + +pub fn constants_module() -> ts::TsModule { + ts::module(vec![ + ts::const_number("RADROOTS_USERNAME_MIN_LEN", 3), + ts::const_number("RADROOTS_USERNAME_MAX_LEN", 30), + ts::const_decl( + "RADROOTS_USERNAME_REGEX", + None, + TsValue::String(r#"^(?!.*\.\.)(?!\.)(?!.*\.$)[a-z0-9._-]{3,30}$"#.to_owned()), + ), + ]) +} #[cfg(test)] mod tests { - use super::CONSTANTS_TS; + use super::constants_module; #[test] fn preserves_username_constant_exports() { - assert!(CONSTANTS_TS.contains("RADROOTS_USERNAME_MIN_LEN")); - assert!(CONSTANTS_TS.contains("RADROOTS_USERNAME_MAX_LEN")); - assert!(CONSTANTS_TS.contains("RADROOTS_USERNAME_REGEX")); + let rendered = constants_module().render(); + assert!(rendered.contains("RADROOTS_USERNAME_MIN_LEN")); + assert!(rendered.contains("RADROOTS_USERNAME_MAX_LEN")); + assert!(rendered.contains("RADROOTS_USERNAME_REGEX")); } } diff --git a/crates/identity_bindings/src/typescript/constants.ts b/crates/identity_bindings/src/typescript/constants.ts @@ -1,3 +0,0 @@ -export const RADROOTS_USERNAME_MIN_LEN = 3; -export const RADROOTS_USERNAME_MAX_LEN = 30; -export const RADROOTS_USERNAME_REGEX = "^(?!.*\.\.)(?!\.)(?!.*\.$)[a-z0-9._-]{3,30}$";