commit 1be0b62f9acbce24bfd4041737af67d1058da40b
parent f0481a5d73a9c350c64ef546e4198287fbead814
Author: triesap <tyson@radroots.org>
Date: Fri, 23 May 2025 02:38:10 +0000
workspace: add nostr events models and build.rs script
Diffstat:
7 files changed, 377 insertions(+), 6 deletions(-)
diff --git a/Cargo.toml b/Cargo.toml
@@ -9,4 +9,4 @@ edition = "2021"
serde = "1.0"
serde_json = "1.0"
thiserror = "1.0"
-typeshare = "1.0.0"
-\ No newline at end of file
+typeshare = "1.0.0"
diff --git a/bindings/ts/package.json b/bindings/ts/package.json
@@ -11,12 +11,11 @@
"scripts": {
"gen:index": "echo \"// Generated @radroots/radroots-common-bindings\" > index.ts && for f in *.ts; do fn=$(basename \"$f\" .ts); [ \"$fn\" != \"index\" ] && echo \"export * from './$fn';\" >> index.ts; done",
"gen:schema": "ts-to-zod types.ts schema.ts",
- "gen:types": "command -v typeshare >/dev/null && typeshare ../../src --lang=typescript --output-file=types.ts || echo 'Skipping typeshare (not installed)'",
- "gen": "npm run gen:types && npm run gen:schema && npm run gen:index",
- "build": "tsc",
- "postbuild": "npm run gen:index"
+ "prebuild": "rimraf dist && npm run gen:schema && npm run gen:index",
+ "build": "tsc"
},
"devDependencies": {
+ "rimraf": "^6.0.1",
"ts-to-zod": "^3.15.0"
},
"dependencies": {
diff --git a/bindings/ts/schema.ts b/bindings/ts/schema.ts
@@ -75,3 +75,108 @@ export const listingOrderRequestSchema = z.object({
event: listingOrderRequestEventSchema,
payload: listingOrderRequestPayloadSchema,
});
+
+export const radrootsNostrEventSchema = z.object({
+ id: z.string(),
+ author: z.string(),
+ created_at: z.number(),
+ kind: z.number(),
+ tags: z.array(z.array(z.string())),
+ content: z.string(),
+ sig: z.string(),
+});
+
+export const radrootsNostrEvent0DataMetadataSchema = z.object({
+ name: z.string(),
+ display_name: z.string().optional(),
+ nip05: z.string().optional(),
+ about: z.string().optional(),
+});
+
+export const radrootsNostrEvent0DataSchema = z.object({
+ published_at: z.number(),
+ metadata: radrootsNostrEvent0DataMetadataSchema,
+});
+
+export const radrootsNostrEvent0Schema = z.object({
+ event: radrootsNostrEventSchema,
+ data: radrootsNostrEvent0DataSchema,
+});
+
+export const radrootsNostrEventRefSchema = z.object({
+ ref_id: z.string(),
+ ref_author: z.string(),
+ ref_kind: z.number(),
+ ref_d_tag: z.string().optional(),
+});
+
+export const radrootsNostrEvent1111DataSchema = z.object({
+ published_at: z.number(),
+ root: radrootsNostrEventRefSchema,
+ parent: radrootsNostrEventRefSchema,
+ content: z.string(),
+});
+
+export const radrootsNostrEvent1111Schema = z.object({
+ event: radrootsNostrEventSchema,
+ data: radrootsNostrEvent1111DataSchema,
+});
+
+export const radrootsNostrEvent3DataFollowSchema = z.object({
+ published_at: z.number(),
+ pubkey: z.string(),
+ relay_url: z.string().optional(),
+ petname: z.string().optional(),
+});
+
+export const radrootsNostrEvent3DataSchema = z.object({
+ following: z.array(radrootsNostrEvent3DataFollowSchema),
+});
+
+export const radrootsNostrEvent3Schema = z.object({
+ event: radrootsNostrEventSchema,
+ data: radrootsNostrEvent3DataSchema,
+});
+
+export const radrootsNostrEvent30402DataSchema = z.object({
+ published_at: z.number(),
+ d_tag: z.string(),
+ title: z.string(),
+ summary: z.string(),
+ images: z.array(z.string()),
+ location_address: z.string(),
+ location_city: z.string(),
+ location_region: z.string(),
+ location_country: z.string(),
+ location_lat: z.string(),
+ location_lng: z.string(),
+ location_geohash: z.string(),
+ product_kind: z.string(),
+ product_category: z.string(),
+ product_process: z.string(),
+ product_lot: z.string(),
+ product_profile: z.string(),
+ product_year: z.string(),
+ product_quantity_amt: z.string(),
+ product_quantity_unit: z.string(),
+ product_price_amt: z.string(),
+ product_price_cur: z.string(),
+ product_price_qty_amt: z.string(),
+ product_price_qty_unit: z.string(),
+});
+
+export const radrootsNostrEvent30402Schema = z.object({
+ event: radrootsNostrEventSchema,
+ data: radrootsNostrEvent30402DataSchema,
+});
+
+export const radrootsNostrEvent7DataSchema = z.object({
+ published_at: z.number(),
+ root: radrootsNostrEventRefSchema,
+ content: z.string(),
+});
+
+export const radrootsNostrEvent7Schema = z.object({
+ event: radrootsNostrEventSchema,
+ data: radrootsNostrEvent7DataSchema,
+});
diff --git a/bindings/ts/types.ts b/bindings/ts/types.ts
@@ -77,3 +77,108 @@ export interface ListingOrderRequest {
payload: ListingOrderRequestPayload;
}
+export interface RadrootsNostrEvent {
+ id: string;
+ author: string;
+ created_at: number;
+ kind: number;
+ tags: string[][];
+ content: string;
+ sig: string;
+}
+
+export interface RadrootsNostrEvent0DataMetadata {
+ name: string;
+ display_name?: string;
+ nip05?: string;
+ about?: string;
+}
+
+export interface RadrootsNostrEvent0Data {
+ published_at: number;
+ metadata: RadrootsNostrEvent0DataMetadata;
+}
+
+export interface RadrootsNostrEvent0 {
+ event: RadrootsNostrEvent;
+ data: RadrootsNostrEvent0Data;
+}
+
+export interface RadrootsNostrEventRef {
+ ref_id: string;
+ ref_author: string;
+ ref_kind: number;
+ ref_d_tag?: string;
+}
+
+export interface RadrootsNostrEvent1111Data {
+ published_at: number;
+ root: RadrootsNostrEventRef;
+ parent: RadrootsNostrEventRef;
+ content: string;
+}
+
+export interface RadrootsNostrEvent1111 {
+ event: RadrootsNostrEvent;
+ data: RadrootsNostrEvent1111Data;
+}
+
+export interface RadrootsNostrEvent3DataFollow {
+ published_at: number;
+ pubkey: string;
+ relay_url?: string;
+ petname?: string;
+}
+
+export interface RadrootsNostrEvent3Data {
+ following: RadrootsNostrEvent3DataFollow[];
+}
+
+export interface RadrootsNostrEvent3 {
+ event: RadrootsNostrEvent;
+ data: RadrootsNostrEvent3Data;
+}
+
+export interface RadrootsNostrEvent30402Data {
+ published_at: number;
+ d_tag: string;
+ title: string;
+ summary: string;
+ images: string[];
+ location_address: string;
+ location_city: string;
+ location_region: string;
+ location_country: string;
+ location_lat: string;
+ location_lng: string;
+ location_geohash: string;
+ product_kind: string;
+ product_category: string;
+ product_process: string;
+ product_lot: string;
+ product_profile: string;
+ product_year: string;
+ product_quantity_amt: string;
+ product_quantity_unit: string;
+ product_price_amt: string;
+ product_price_cur: string;
+ product_price_qty_amt: string;
+ product_price_qty_unit: string;
+}
+
+export interface RadrootsNostrEvent30402 {
+ event: RadrootsNostrEvent;
+ data: RadrootsNostrEvent30402Data;
+}
+
+export interface RadrootsNostrEvent7Data {
+ published_at: number;
+ root: RadrootsNostrEventRef;
+ content: string;
+}
+
+export interface RadrootsNostrEvent7 {
+ event: RadrootsNostrEvent;
+ data: RadrootsNostrEvent7Data;
+}
+
diff --git a/build.rs b/build.rs
@@ -0,0 +1,27 @@
+use std::process::{Command, Stdio};
+
+fn main() {
+ let status_typeshare = Command::new("typeshare")
+ .args(["--lang", "typescript", "--output-file", "bindings/ts/types.ts", "src"])
+ .status()
+ .expect("failed to run typeshare");
+
+ if !status_typeshare.success() {
+ panic!("typeshare generation failed");
+ }
+
+ let status_ts_build = Command::new("npm")
+ .arg("run")
+ .arg("build")
+ .current_dir("bindings/ts")
+ .stdout(Stdio::inherit())
+ .stderr(Stdio::inherit())
+ .status()
+ .expect("failed to run `npm run build`");
+
+ if !status_ts_build.success() {
+ panic!("typescript bindings build failed");
+ }
+
+ println!("cargo:rerun-if-changed=src/");
+}
diff --git a/src/models/events.rs b/src/models/events.rs
@@ -0,0 +1,135 @@
+use serde::{Deserialize, Serialize};
+use typeshare::typeshare;
+
+#[typeshare]
+#[derive(Clone, Debug, Serialize, Deserialize)]
+pub struct RadrootsNostrEvent {
+ pub id: String,
+ pub author: String,
+ pub created_at: u32,
+ pub kind: u32,
+ pub tags: Vec<Vec<String>>,
+ pub content: String,
+ pub sig: String,
+}
+
+#[typeshare]
+#[derive(Clone, Debug, Serialize, Deserialize)]
+pub struct RadrootsNostrEventRef {
+ pub ref_id: String,
+ pub ref_author: String,
+ pub ref_kind: u32,
+ pub ref_d_tag: Option<String>,
+}
+
+#[typeshare]
+#[derive(Clone, Debug, Serialize, Deserialize)]
+pub struct RadrootsNostrEvent0 {
+ pub event: RadrootsNostrEvent,
+ pub data: RadrootsNostrEvent0Data,
+}
+
+#[typeshare]
+#[derive(Clone, Debug, Serialize, Deserialize)]
+pub struct RadrootsNostrEvent0DataMetadata {
+ pub name: String,
+ pub display_name: Option<String>,
+ pub nip05: Option<String>,
+ pub about: Option<String>,
+}
+
+#[typeshare]
+#[derive(Clone, Debug, Serialize, Deserialize)]
+pub struct RadrootsNostrEvent0Data {
+ pub published_at: u32,
+ pub metadata: RadrootsNostrEvent0DataMetadata,
+}
+
+#[typeshare]
+#[derive(Clone, Debug, Serialize, Deserialize)]
+pub struct RadrootsNostrEvent3 {
+ pub event: RadrootsNostrEvent,
+ pub data: RadrootsNostrEvent3Data,
+}
+
+#[typeshare]
+#[derive(Clone, Debug, Serialize, Deserialize)]
+pub struct RadrootsNostrEvent3Data {
+ pub following: Vec<RadrootsNostrEvent3DataFollow>,
+}
+
+#[typeshare]
+#[derive(Clone, Debug, Serialize, Deserialize)]
+pub struct RadrootsNostrEvent3DataFollow {
+ pub published_at: u32,
+ pub pubkey: String,
+ pub relay_url: Option<String>,
+ pub petname: Option<String>,
+}
+
+#[typeshare]
+#[derive(Clone, Debug, Serialize, Deserialize)]
+pub struct RadrootsNostrEvent7 {
+ pub event: RadrootsNostrEvent,
+ pub data: RadrootsNostrEvent7Data,
+}
+
+#[typeshare]
+#[derive(Clone, Debug, Serialize, Deserialize)]
+pub struct RadrootsNostrEvent7Data {
+ pub published_at: u32,
+ pub root: RadrootsNostrEventRef,
+ pub content: String,
+}
+
+#[typeshare]
+#[derive(Clone, Debug, Serialize, Deserialize)]
+pub struct RadrootsNostrEvent1111 {
+ pub event: RadrootsNostrEvent,
+ pub data: RadrootsNostrEvent1111Data,
+}
+
+#[typeshare]
+#[derive(Clone, Debug, Serialize, Deserialize)]
+pub struct RadrootsNostrEvent1111Data {
+ pub published_at: u32,
+ pub root: RadrootsNostrEventRef,
+ pub parent: RadrootsNostrEventRef,
+ pub content: String,
+}
+
+#[typeshare]
+#[derive(Clone, Debug, Serialize, Deserialize)]
+pub struct RadrootsNostrEvent30402 {
+ pub event: RadrootsNostrEvent,
+ pub data: RadrootsNostrEvent30402Data,
+}
+
+#[typeshare]
+#[derive(Clone, Debug, Serialize, Deserialize)]
+pub struct RadrootsNostrEvent30402Data {
+ pub published_at: u32,
+ pub d_tag: String,
+ pub title: String,
+ pub summary: String,
+ pub images: Vec<String>,
+ pub location_address: String,
+ pub location_city: String,
+ pub location_region: String,
+ pub location_country: String,
+ pub location_lat: String,
+ pub location_lng: String,
+ pub location_geohash: String,
+ pub product_kind: String,
+ pub product_category: String,
+ pub product_process: String,
+ pub product_lot: String,
+ pub product_profile: String,
+ pub product_year: String,
+ pub product_quantity_amt: String,
+ pub product_quantity_unit: String,
+ pub product_price_amt: String,
+ pub product_price_cur: String,
+ pub product_price_qty_amt: String,
+ pub product_price_qty_unit: String,
+}
diff --git a/src/models/mod.rs b/src/models/mod.rs
@@ -1,2 +1,3 @@
+pub mod events;
pub mod listing_order;
pub mod listing_order_request;