commit d15d2d495fb87b5a14ce0618ce8c72203ad2d855
parent 82281752faf73e29713315339cb4fd0d72e49250
Author: triesap <tyson@radroots.org>
Date: Sat, 26 Apr 2025 22:15:01 +0000
workspace: add `bindings` npm module for generated types and listing order models
Diffstat:
7 files changed, 122 insertions(+), 0 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -7,3 +7,5 @@ git-diff.txt
.DS_Store
*.pem
+
+bindings/*.ts
diff --git a/Cargo.toml b/Cargo.toml
@@ -4,3 +4,9 @@ version = "0.1.0"
authors = ["Radroots Authors"]
license = "AGPLv3"
edition = "2024"
+
+[dependencies]
+serde = "1.0"
+serde_json = "1.0"
+thiserror = "1.0"
+typeshare = "1.0.0"
+\ No newline at end of file
diff --git a/bindings/package.json b/bindings/package.json
@@ -0,0 +1,8 @@
+{
+ "name": "@radroots/radroots-common-bindings",
+ "version": "1.0.0",
+ "main": "types.ts",
+ "types": "types.ts",
+ "sideEffects": false,
+ "license": "AGPLv3"
+}
+\ No newline at end of file
diff --git a/src/lib.rs b/src/lib.rs
@@ -1,3 +1,5 @@
pub const KIND_JOB_REQUEST: u16 = 5300;
pub const KIND_JOB_RESPONSE: u16 = 6300;
pub const KIND_APPLICATION_HANDLER: u16 = 31990;
+
+pub mod models;
diff --git a/src/models/listing_order.rs b/src/models/listing_order.rs
@@ -0,0 +1,60 @@
+use serde::{Deserialize, Serialize};
+use typeshare::typeshare;
+
+#[typeshare]
+#[derive(Debug, Serialize, Deserialize, Clone)]
+pub struct ListingOrder {
+ pub quantity: ListingOrderQuantity,
+ pub price: ListingOrderPrice,
+ pub discounts: Vec<ListingOrderDiscount>,
+ pub subtotal: ListingOrderSubtotal,
+ pub total: ListingOrderTotal,
+}
+
+#[typeshare]
+#[derive(Debug, Serialize, Deserialize, Clone)]
+pub struct ListingOrderQuantity {
+ pub amount: f64,
+ pub unit: String,
+ pub label: String,
+}
+
+#[typeshare]
+#[derive(Debug, Serialize, Deserialize, Clone)]
+pub struct ListingOrderPrice {
+ pub amount: f64,
+ pub currency: String,
+ pub quantity_amount: f64,
+ pub quantity_unit: String,
+}
+
+#[typeshare]
+#[derive(Debug, Serialize, Deserialize, Clone)]
+pub struct ListingOrderDiscount {
+ pub discount_type: String,
+ pub threshold: Option<f64>,
+ pub threshold_unit: Option<String>,
+ pub discount_per_unit: Option<f64>,
+ pub discount_unit: Option<String>,
+ pub discount_percent: Option<f64>,
+ pub discount_amount: f64,
+ pub currency: String,
+}
+
+#[typeshare]
+#[derive(Debug, Serialize, Deserialize, Clone)]
+pub struct ListingOrderSubtotal {
+ pub price_amount: f64,
+ pub price_currency: String,
+ pub quantity_amount: f64,
+ pub quantity_unit: String,
+}
+
+#[typeshare]
+#[derive(Debug, Serialize, Deserialize, Clone)]
+pub struct ListingOrderTotal {
+ pub price_amount: f64,
+ pub price_currency: String,
+ pub quantity_amount: f64,
+ pub quantity_unit: String,
+}
diff --git a/src/models/listing_order_request.rs b/src/models/listing_order_request.rs
@@ -0,0 +1,40 @@
+use serde::{Deserialize, Serialize};
+use typeshare::typeshare;
+
+#[typeshare]
+#[derive(Debug, Serialize, Deserialize)]
+pub struct ListingOrderRequestQuantity {
+ pub amount: f64,
+ pub unit: String,
+ pub label: String,
+ pub count: u32,
+}
+
+#[typeshare]
+#[derive(Debug, Serialize, Deserialize)]
+pub struct ListingOrderRequestPrice {
+ pub amount: f64,
+ pub currency: String,
+ pub quantity_amount: f64,
+ pub quantity_unit: String,
+}
+
+#[typeshare]
+#[derive(Debug, Serialize, Deserialize)]
+pub struct ListingOrderRequestPayload {
+ pub price: ListingOrderRequestPrice,
+ pub quantity: ListingOrderRequestQuantity,
+}
+
+#[typeshare]
+#[derive(Debug, Serialize, Deserialize)]
+pub struct ListingOrderRequestEvent {
+ pub id: String,
+}
+
+#[typeshare]
+#[derive(Debug, Serialize, Deserialize)]
+pub struct ListingOrderRequest {
+ pub event: ListingOrderRequestEvent,
+ pub payload: ListingOrderRequestPayload,
+}
diff --git a/src/models/mod.rs b/src/models/mod.rs
@@ -0,0 +1,2 @@
+pub mod listing_order;
+pub mod listing_order_request;