sdk

Radroots SDK and bindings
git clone https://radroots.dev/git/sdk.git
Log | Files | Refs | README

commit ca443903b9cfbaba3f97ec3826f44a3982075553
parent 536636a0fc5d10b541edba5cdeb9a7fcf8705993
Author: triesap <tyson@radroots.org>
Date:   Wed, 24 Jun 2026 06:58:06 +0000

dto: close core registry binding output

- render registry declarations in stable exported-name order
- remove the core binding crate dependency on the hand-written binding model
- retarget core binding tests to the generated package artifact
- regenerate core TypeScript output from source descriptors

Diffstat:
MCargo.lock | 1-
Mcrates/core_bindings/Cargo.toml | 1-
Mcrates/core_bindings/src/lib.rs | 122++++++-------------------------------------------------------------------------
Mpackages/core-bindings/src/generated/types.ts | 14+++++++-------
Mtools/xtask/src/dto_render.rs | 14+++++++++-----
5 files changed, 24 insertions(+), 128 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock @@ -1685,7 +1685,6 @@ name = "radroots_core_bindings" version = "0.1.0" dependencies = [ "radroots_core", - "radroots_sdk_binding_model", ] [[package]] diff --git a/crates/core_bindings/Cargo.toml b/crates/core_bindings/Cargo.toml @@ -9,5 +9,4 @@ 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,122 +1,16 @@ pub use radroots_core as upstream; -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_module; + const GENERATED_TYPES_TS: &str = + include_str!("../../../packages/core-bindings/src/generated/types.ts"); #[test] - fn preserves_core_type_exports() { - let rendered = types_module().render(); - assert!(rendered.contains("export type RadrootsCoreMoney")); - assert!(rendered.contains("export type RadrootsCoreQuantityPrice")); - assert!(rendered.contains("\"each\"")); + fn generated_core_types_are_source_rendered() { + assert!(GENERATED_TYPES_TS.contains("export type RadrootsCoreMoney")); + assert!(GENERATED_TYPES_TS.contains("export type RadrootsCoreQuantityPrice")); + assert!(GENERATED_TYPES_TS.contains("export type RadrootsCoreUnitDimension")); + assert!(GENERATED_TYPES_TS.contains("label?: string | null")); + assert!(!GENERATED_TYPES_TS.contains("label: string | null")); } } diff --git a/packages/core-bindings/src/generated/types.ts b/packages/core-bindings/src/generated/types.ts @@ -4,22 +4,22 @@ export type RadrootsCoreCurrency = string; export type RadrootsCoreDecimal = string; -export type RadrootsCoreDiscountScope = "bin" | "order_total"; - -export type RadrootsCoreUnit = "each" | "kg" | "g" | "oz" | "lb" | "l" | "ml"; +export type RadrootsCoreDiscount = { scope: RadrootsCoreDiscountScope, threshold: RadrootsCoreDiscountThreshold, value: RadrootsCoreDiscountValue, }; -export type RadrootsCoreQuantity = { amount: string, unit: RadrootsCoreUnit, label?: string | null, }; +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 RadrootsCoreDiscountValue = { kind: "money_per_bin", amount: RadrootsCoreMoney, } | { kind: "percent", amount: RadrootsCorePercent, }; - -export type RadrootsCoreDiscount = { scope: RadrootsCoreDiscountScope, threshold: RadrootsCoreDiscountThreshold, value: RadrootsCoreDiscountValue, }; +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/tools/xtask/src/dto_render.rs b/tools/xtask/src/dto_render.rs @@ -81,11 +81,15 @@ pub fn render_registry_types( ) -> Result<DtoTypesModule, String> { let mut imports = BTreeMap::<String, BTreeSet<String>>::new(); let mut declarations = Vec::new(); + let mut type_defs = registry + .types_by_id + .iter() + .filter(|(type_id, _)| !options.external_imports.contains_key(type_id)) + .collect::<Vec<_>>(); - for (type_id, type_def) in &registry.types_by_id { - if options.external_imports.contains_key(type_id) { - continue; - } + type_defs.sort_by(|(_, left), (_, right)| type_name(left).cmp(type_name(right))); + + for (type_id, type_def) in type_defs { declarations.push(render_type_def( *type_id, type_def, @@ -617,7 +621,7 @@ mod tests { ); assert_eq!( rendered.body_ts(), - "export type Envelope<T> = { value: T, };\n\nexport type SyntheticThing = { external: ExternalThing, maybeCount?: string | null, point: [number, number], envelope: Envelope<ExternalThing>, };\n\nexport type SyntheticMode = \"ready\" | \"done\";\n\nexport type SyntheticEvent = { type: \"created\", payload: { id: string, }, } | { type: \"archived\", payload: { reason?: string | null, }, };" + "export type Envelope<T> = { value: T, };\n\nexport type SyntheticEvent = { type: \"created\", payload: { id: string, }, } | { type: \"archived\", payload: { reason?: string | null, }, };\n\nexport type SyntheticMode = \"ready\" | \"done\";\n\nexport type SyntheticThing = { external: ExternalThing, maybeCount?: string | null, point: [number, number], envelope: Envelope<ExternalThing>, };" ); }