lib

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

commit 08d6985262ecd4e040b27468679e6d50a863a05d
parent 32f2ff8515a239a61fe9f7945e6d8a68165e59dd
Author: triesap <tyson@radroots.org>
Date:   Mon, 11 Aug 2025 12:41:15 -0700

events: create event model hierarchy and add `ts` bindings

Diffstat:
Mbindings/ts/package.json | 6+++---
Abindings/ts/src/events/schema.ts | 133+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Abindings/ts/src/events/types.ts | 17+++++++++++++++++
Mbindings/ts/src/index.ts | 6+++---
Dbindings/ts/src/schema.ts | 205-------------------------------------------------------------------------------
Mbindings/ts/src/types.ts | 192+++++++++++++++++--------------------------------------------------------------
Aprompt.txt | 115+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/events/comment/models.rs | 26++++++++++++++++++++++++++
Asrc/events/follow/models.rs | 32++++++++++++++++++++++++++++++++
Asrc/events/lib.rs | 10++++++++++
Asrc/events/listing/models.rs | 110+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/events/mod.rs | 32++++++++++++++++++++++++++++++++
Asrc/events/profile/models.rs | 33+++++++++++++++++++++++++++++++++
Asrc/events/reaction/models.rs | 25+++++++++++++++++++++++++
Msrc/lib.rs | 2++
Dsrc/models/events.rs | 139-------------------------------------------------------------------------------
Dsrc/models/listing_order.rs | 61-------------------------------------------------------------
Dsrc/models/listing_order_request.rs | 40----------------------------------------
Msrc/models/mod.rs | 6+-----
19 files changed, 582 insertions(+), 608 deletions(-)

diff --git a/bindings/ts/package.json b/bindings/ts/package.json @@ -26,12 +26,12 @@ "clean": "rimraf dist", "dev": "npm run watch", "watch": "tsc -w", - "gen:index": "echo \"// Generated @radroots/radroots-common-bindings\" > src/index.ts && for f in src/*.ts; do fn=$(basename \"$f\" .ts); [ \"$fn\" != \"index\" ] && echo \"export * from './$fn.js';\" >> src/index.ts; done", - "gen:schema": "ts-to-zod src/types.ts src/schema.ts", "gen:types": "typeshare --lang typescript --output-file=src/types.ts ../../src", - "gen": "npm run gen:types && npm run gen:schema && npm run gen:index" + "gen:exports": "gen-package-exports.js --is_module", + "gen": "npm run gen:types && npm run gen:exports" }, "devDependencies": { + "@radroots/dev": "*", "@radroots/tsconfig": "*", "rimraf": "^6.0.1", "ts-to-zod": "^3.15.0" diff --git a/bindings/ts/src/events/schema.ts b/bindings/ts/src/events/schema.ts @@ -0,0 +1,133 @@ +import { z } from "zod"; + +export const radroots_nostr_event_ref_schema = z.object({ + id: z.string(), + author: z.string(), + kind: z.number(), + d_tag: z.string().optional(), + relays: z.array(z.string()).optional() +}); + +export const radroots_listing_image_schema = z.object({ + url: z.string(), + size: z.object({ + w: z.number(), + h: z.number() + }).optional() +}); + +export const radroots_listing_location_schema = z.object({ + primary: z.string(), + city: z.string().optional(), + region: z.string().optional(), + country: z.string().optional(), + lat: z.number().optional(), + lng: z.number().optional(), + geohash: z.string().optional() +}); + +export const radroots_listing_discount_schema = z.union([ + z.object({ + quantity: z.object({ + ref_quantity: z.string(), + threshold: z.string(), + value: z.string(), + currency: z.string() + }) + }), + z.object({ + mass: z.object({ + unit: z.string(), + threshold: z.string(), + threshold_unit: z.string(), + value: z.string(), + currency: z.string() + }) + }), + z.object({ + subtotal: z.object({ + threshold: z.string(), + currency: z.string(), + value: z.string(), + measure: z.string() + }) + }), + z.object({ + total: z.object({ + total_min: z.string(), + value: z.string(), + measure: z.string() + }) + }) +]); + +export const radroots_listing_price_schema = z.object({ + amt: z.string(), + currency: z.string(), + qty_amt: z.string(), + qty_unit: z.string(), + qty_key: z.string() +}); + +export const radroots_listing_quantity_schema = z.object({ + amt: z.string(), + unit: z.string(), + label: z.string().optional() +}); + +export const radroots_listing_product_schema = z.object({ + key: z.string(), + title: z.string(), + category: z.string(), + summary: z.string().optional(), + process: z.string().optional(), + lot: z.string().optional(), + location: z.string().optional(), + profile: z.string().optional(), + year: z.string().optional() +}); + +export const radroots_listing_schema = z.object({ + d_tag: z.string(), + product: radroots_listing_product_schema, + quantities: z.array(radroots_listing_quantity_schema), + prices: z.array(radroots_listing_price_schema), + discounts: z.array(radroots_listing_discount_schema).optional(), + location: radroots_listing_location_schema.optional(), + images: z.array(radroots_listing_image_schema).optional() +}); + +export const radroots_profile_schema = z.object({ + name: z.string(), + display_name: z.string().optional(), + nip05: z.string().optional(), + about: z.string().optional(), + website: z.string().optional(), + picture: z.string().optional(), + banner: z.string().optional(), + lud06: z.string().optional(), + lud16: z.string().optional(), + bot: z.string().optional() +}); + +export const radroots_comment_schema = z.object({ + root: radroots_nostr_event_ref_schema, + parent: radroots_nostr_event_ref_schema, + content: z.string() +}); + +export const radroots_reaction_schema = z.object({ + root: radroots_nostr_event_ref_schema, + content: z.string() +}); + +export const radroots_follow_profile_schema = z.object({ + published_at: z.number(), + public_key: z.string(), + relay_url: z.string().optional(), + contact_name: z.string().optional() +}); + +export const radroots_follow_schema = z.object({ + list: z.array(radroots_follow_profile_schema) +}); diff --git a/bindings/ts/src/events/types.ts b/bindings/ts/src/events/types.ts @@ -0,0 +1,16 @@ +import { z } from "zod"; +import { radroots_comment_schema, radroots_follow_profile_schema, radroots_follow_schema, radroots_listing_discount_schema, radroots_listing_image_schema, radroots_listing_location_schema, radroots_listing_price_schema, radroots_listing_product_schema, radroots_listing_quantity_schema, radroots_listing_schema, radroots_nostr_event_ref_schema, radroots_profile_schema, radroots_reaction_schema } from "./schema.js"; + +export type RadrootsNostrEventRef = z.infer<typeof radroots_nostr_event_ref_schema>; +export type RadrootsListingImage = z.infer<typeof radroots_listing_image_schema>; +export type RadrootsListingLocation = z.infer<typeof radroots_listing_location_schema>; +export type RadrootsListingDiscount = z.infer<typeof radroots_listing_discount_schema>; +export type RadrootsListingPrice = z.infer<typeof radroots_listing_price_schema>; +export type RadrootsListingQuantity = z.infer<typeof radroots_listing_quantity_schema>; +export type RadrootsListingProduct = z.infer<typeof radroots_listing_product_schema>; +export type RadrootsListing = z.infer<typeof radroots_listing_schema>; +export type RadrootsProfile = z.infer<typeof radroots_profile_schema>; +export type RadrootsComment = z.infer<typeof radroots_comment_schema>; +export type RadrootsReaction = z.infer<typeof radroots_reaction_schema>; +export type RadrootsFollowProfile = z.infer<typeof radroots_follow_profile_schema>; +export type RadrootsFollow = z.infer<typeof radroots_follow_schema>; +\ No newline at end of file diff --git a/bindings/ts/src/index.ts b/bindings/ts/src/index.ts @@ -1,3 +1,3 @@ -// Generated @radroots/radroots-common-bindings -export * from './schema.js'; -export * from './types.js'; +export * from "./events/schema.js" +export * from "./events/types.js" +export * from "./types.js" diff --git a/bindings/ts/src/schema.ts b/bindings/ts/src/schema.ts @@ -1,205 +0,0 @@ -// Generated by ts-to-zod -import { z } from "zod"; - -export const listingOrderQuantitySchema = z.object({ - amount: z.number(), - unit: z.string(), - label: z.string(), - count: z.number(), -}); - -export const listingOrderPriceSchema = z.object({ - amount: z.number(), - currency: z.string(), - quantity_amount: z.number(), - quantity_unit: z.string(), -}); - -export const listingOrderDiscountSchema = z.object({ - discount_type: z.string(), - threshold: z.number().optional(), - threshold_unit: z.string().optional(), - discount_per_unit: z.number().optional(), - discount_unit: z.string().optional(), - discount_percent: z.number().optional(), - discount_amount: z.number(), - currency: z.string(), -}); - -export const listingOrderSubtotalSchema = z.object({ - price_amount: z.number(), - price_currency: z.string(), - quantity_amount: z.number(), - quantity_unit: z.string(), -}); - -export const listingOrderTotalSchema = z.object({ - price_amount: z.number(), - price_currency: z.string(), - quantity_amount: z.number(), - quantity_unit: z.string(), -}); - -export const listingOrderSchema = z.object({ - quantity: listingOrderQuantitySchema, - price: listingOrderPriceSchema, - discounts: z.array(listingOrderDiscountSchema), - subtotal: listingOrderSubtotalSchema, - total: listingOrderTotalSchema, -}); - -export const listingOrderRequestEventSchema = z.object({ - id: z.string(), -}); - -export const listingOrderRequestPriceSchema = z.object({ - amount: z.number(), - currency: z.string(), - quantity_amount: z.number(), - quantity_unit: z.string(), -}); - -export const listingOrderRequestQuantitySchema = z.object({ - amount: z.number(), - unit: z.string(), - label: z.string(), - count: z.number(), -}); - -export const listingOrderRequestPayloadSchema = z.object({ - price: listingOrderRequestPriceSchema, - quantity: listingOrderRequestQuantitySchema, -}); - -export const listingOrderRequestSchema = z.object({ - event: listingOrderRequestEventSchema, - payload: listingOrderRequestPayloadSchema, -}); - -export const radrootsIndexShardMetadataSchema = z.object({ - file: z.string(), - count: z.number(), - first_id: z.string(), - last_id: z.string(), - first_published_at: z.number(), - last_published_at: z.number(), - sha256: z.string(), -}); - -export const radrootsIndexManifestSchema = z.object({ - country: z.string(), - total: z.number(), - shard_size: z.number(), - first_published_at: z.number(), - last_published_at: z.number(), - shards: z.array(radrootsIndexShardMetadataSchema), -}); - -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 radrootsListingEventDataSchema = z.object({ - id: z.string(), - author: z.string(), - 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 radrootsListingEventSchema = z.object({ - event: radrootsNostrEventSchema, - data: radrootsListingEventDataSchema, -}); - -export const radrootsMetadataEventDataMetadataSchema = z.object({ - name: z.string(), - display_name: z.string().optional(), - nip05: z.string().optional(), - about: z.string().optional(), -}); - -export const radrootsMetadataEventDataSchema = z.object({ - id: z.string(), - public_key: z.string(), - published_at: z.number(), - metadata: radrootsMetadataEventDataMetadataSchema, -}); - -export const radrootsMetadataEventSchema = z.object({ - event: radrootsNostrEventSchema, - data: radrootsMetadataEventDataSchema, -}); - -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 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/src/types.ts b/bindings/ts/src/types.ts @@ -1,80 +1,41 @@ +import { RadrootsComment, RadrootsFollow, RadrootsListing, RadrootsProfile, RadrootsReaction } from "./events/types.js"; + /* Generated by typeshare 1.13.2 */ -export interface ListingOrderQuantity { - amount: number; - unit: string; - label: string; - count: number; -} - -export interface ListingOrderPrice { - amount: number; - currency: string; - quantity_amount: number; - quantity_unit: string; -} - -export interface ListingOrderDiscount { - discount_type: string; - threshold?: number; - threshold_unit?: string; - discount_per_unit?: number; - discount_unit?: string; - discount_percent?: number; - discount_amount: number; - currency: string; -} - -export interface ListingOrderSubtotal { - price_amount: number; - price_currency: string; - quantity_amount: number; - quantity_unit: string; -} - -export interface ListingOrderTotal { - price_amount: number; - price_currency: string; - quantity_amount: number; - quantity_unit: string; -} - -export interface ListingOrder { - quantity: ListingOrderQuantity; - price: ListingOrderPrice; - discounts: ListingOrderDiscount[]; - subtotal: ListingOrderSubtotal; - total: ListingOrderTotal; -} - -export interface ListingOrderRequestEvent { +export interface RadrootsNostrEvent { id: string; + author: string; + created_at: number; + kind: number; + tags: string[][]; + content: string; + sig: string; } -export interface ListingOrderRequestPrice { - amount: number; - currency: string; - quantity_amount: number; - quantity_unit: string; +export interface RadrootsCommentEventMetadata { + id: string; + author: string; + published_at: number; + comment: RadrootsComment; } -export interface ListingOrderRequestQuantity { - amount: number; - unit: string; - label: string; - count: number; +export interface RadrootsCommentEventIndex { + event: RadrootsNostrEvent; + metadata: RadrootsCommentEventMetadata; } -export interface ListingOrderRequestPayload { - price: ListingOrderRequestPrice; - quantity: ListingOrderRequestQuantity; +export interface RadrootsFollowEventMetadata { + id: string; + author: string; + published_at: number; + follow: RadrootsFollow; } -export interface ListingOrderRequest { - event: ListingOrderRequestEvent; - payload: ListingOrderRequestPayload; +export interface RadrootsFollowEventIndex { + event: RadrootsNostrEvent; + metadata: RadrootsFollowEventMetadata; } export interface RadrootsIndexShardMetadata { @@ -96,112 +57,39 @@ export interface RadrootsIndexManifest { shards: RadrootsIndexShardMetadata[]; } -export interface RadrootsNostrEvent { - id: string; - author: string; - created_at: number; - kind: number; - tags: string[][]; - content: string; - sig: string; -} - -export interface RadrootsListingEventData { +export interface RadrootsListingEventMetadata { id: string; author: string; 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; + listing: RadrootsListing; } -export interface RadrootsListingEvent { +export interface RadrootsListingEventIndex { event: RadrootsNostrEvent; - data: RadrootsListingEventData; + metadata: RadrootsListingEventMetadata; } -export interface RadrootsMetadataEventDataMetadata { - name: string; - display_name?: string; - nip05?: string; - about?: string; -} - -export interface RadrootsMetadataEventData { +export interface RadrootsProfileEventMetadata { id: string; - public_key: string; - published_at: number; - metadata: RadrootsMetadataEventDataMetadata; -} - -export interface RadrootsMetadataEvent { - event: RadrootsNostrEvent; - data: RadrootsMetadataEventData; -} - -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 { + author: string; published_at: number; - pubkey: string; - relay_url?: string; - petname?: string; -} - -export interface RadrootsNostrEvent3Data { - following: RadrootsNostrEvent3DataFollow[]; + profile: RadrootsProfile; } -export interface RadrootsNostrEvent3 { +export interface RadrootsProfileEventIndex { event: RadrootsNostrEvent; - data: RadrootsNostrEvent3Data; + metadata: RadrootsProfileEventMetadata; } -export interface RadrootsNostrEvent7Data { +export interface RadrootsReactionEventMetadata { + id: string; + author: string; published_at: number; - root: RadrootsNostrEventRef; - content: string; + reaction: RadrootsReaction; } -export interface RadrootsNostrEvent7 { +export interface RadrootsReactionEventIndex { event: RadrootsNostrEvent; - data: RadrootsNostrEvent7Data; + metadata: RadrootsReactionEventMetadata; } diff --git a/prompt.txt b/prompt.txt @@ -0,0 +1,115 @@ + +########## file ########## +src/events/listing/models.rs +########## code ########## +use serde::{Deserialize, Serialize}; +use typeshare::typeshare; +use crate::events::RadrootsNostrEvent; + +#[typeshare] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsListingEventIndex { + pub event: RadrootsNostrEvent, + pub metadata: RadrootsListingEventMetadata, +} + +#[typeshare] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsListingEventMetadata { + pub id: String, + pub author: String, + pub published_at: u32, + pub listing: RadrootsListing, +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsListing { + pub d_tag: String, + pub product: RadrootsListingProduct, + pub quantities: Vec<RadrootsListingQuantity>, + pub prices: Vec<RadrootsListingPrice>, + pub discounts: Option<Vec<RadrootsListingDiscount>>, + pub location: Option<RadrootsListingLocation>, + pub images: Option<Vec<RadrootsListingImage>>, +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsListingProduct { + pub key: String, + pub title: String, + pub category: String, + pub summary: Option<String>, + pub process: Option<String>, + pub lot: Option<String>, + pub location: Option<String>, + pub profile: Option<String>, + pub year: Option<String>, +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsListingQuantity { + pub amt: String, + pub unit: String, + pub label: Option<String>, +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsListingPrice { + pub amt: String, + pub currency: String, + pub qty_amt: String, + pub qty_unit: String, + pub qty_key: String, +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub enum RadrootsListingDiscount { + Quantity { + ref_quantity: String, + threshold: String, + value: String, + currency: String, + }, + Mass { + unit: String, + threshold: String, + threshold_unit: String, + value: String, + currency: String, + }, + Subtotal { + threshold: String, + currency: String, + value: String, + measure: String, + }, + Total { + total_min: String, + value: String, + measure: String, + }, +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsListingLocation { + pub primary: String, + pub city: Option<String>, + pub region: Option<String>, + pub country: Option<String>, + pub lat: Option<f64>, + pub lng: Option<f64>, + pub geohash: Option<String>, +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsListingImage { + pub url: String, + pub size: Option<RadrootsListingImageSize>, +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsListingImageSize { + pub w: u32, + pub h: u32, +} + diff --git a/src/events/comment/models.rs b/src/events/comment/models.rs @@ -0,0 +1,26 @@ +use serde::{Deserialize, Serialize}; +use typeshare::typeshare; +use crate::events::{lib::RadrootsNostrEventRef, RadrootsNostrEvent}; + +#[typeshare] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsCommentEventIndex { + pub event: RadrootsNostrEvent, + pub metadata: RadrootsCommentEventMetadata, +} + +#[typeshare] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsCommentEventMetadata { + pub id: String, + pub author: String, + pub published_at: u32, + pub comment: RadrootsComment, +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsComment { + pub root: RadrootsNostrEventRef, + pub parent: RadrootsNostrEventRef, + pub content: String, +} diff --git a/src/events/follow/models.rs b/src/events/follow/models.rs @@ -0,0 +1,32 @@ +use serde::{Deserialize, Serialize}; +use typeshare::typeshare; +use crate::events::RadrootsNostrEvent; + +#[typeshare] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsFollowEventIndex { + pub event: RadrootsNostrEvent, + pub metadata: RadrootsFollowEventMetadata, +} + +#[typeshare] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsFollowEventMetadata { + pub id: String, + pub author: String, + pub published_at: u32, + pub follow: RadrootsFollow, +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsFollow { + pub list: Vec<RadrootsFollowProfile>, +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsFollowProfile { + pub published_at: u32, + pub public_key: String, + pub relay_url: Option<String>, + pub contact_name: Option<String>, +} diff --git a/src/events/lib.rs b/src/events/lib.rs @@ -0,0 +1,10 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsNostrEventRef { + pub id: String, + pub author: String, + pub kind: u32, + pub d_tag: Option<String>, + pub relays: Option<Vec<String>>, +} diff --git a/src/events/listing/models.rs b/src/events/listing/models.rs @@ -0,0 +1,110 @@ +use serde::{Deserialize, Serialize}; +use typeshare::typeshare; +use crate::events::RadrootsNostrEvent; + +#[typeshare] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsListingEventIndex { + pub event: RadrootsNostrEvent, + pub metadata: RadrootsListingEventMetadata, +} + +#[typeshare] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsListingEventMetadata { + pub id: String, + pub author: String, + pub published_at: u32, + pub listing: RadrootsListing, +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsListing { + pub d_tag: String, + pub product: RadrootsListingProduct, + pub quantities: Vec<RadrootsListingQuantity>, + pub prices: Vec<RadrootsListingPrice>, + pub discounts: Option<Vec<RadrootsListingDiscount>>, + pub location: Option<RadrootsListingLocation>, + pub images: Option<Vec<RadrootsListingImage>>, +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsListingProduct { + pub key: String, + pub title: String, + pub category: String, + pub summary: Option<String>, + pub process: Option<String>, + pub lot: Option<String>, + pub location: Option<String>, + pub profile: Option<String>, + pub year: Option<String>, +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsListingQuantity { + pub amt: String, + pub unit: String, + pub label: Option<String>, +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsListingPrice { + pub amt: String, + pub currency: String, + pub qty_amt: String, + pub qty_unit: String, + pub qty_key: String, +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub enum RadrootsListingDiscount { + Quantity { + ref_quantity: String, + threshold: String, + value: String, + currency: String, + }, + Mass { + unit: String, + threshold: String, + threshold_unit: String, + value: String, + currency: String, + }, + Subtotal { + threshold: String, + currency: String, + value: String, + measure: String, + }, + Total { + total_min: String, + value: String, + measure: String, + }, +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsListingLocation { + pub primary: String, + pub city: Option<String>, + pub region: Option<String>, + pub country: Option<String>, + pub lat: Option<f64>, + pub lng: Option<f64>, + pub geohash: Option<String>, +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsListingImage { + pub url: String, + pub size: Option<RadrootsListingImageSize>, +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsListingImageSize { + pub w: u32, + pub h: u32, +} diff --git a/src/events/mod.rs b/src/events/mod.rs @@ -0,0 +1,32 @@ +pub mod lib; + +pub mod comment { + pub mod models; +} + +pub mod listing { + pub mod models; +} + +pub mod profile { + pub mod models; +} + +pub mod reaction { + pub mod models; +} + +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, +} diff --git a/src/events/profile/models.rs b/src/events/profile/models.rs @@ -0,0 +1,33 @@ +use serde::{Deserialize, Serialize}; +use typeshare::typeshare; +use crate::events::RadrootsNostrEvent; + +#[typeshare] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsProfileEventIndex { + pub event: RadrootsNostrEvent, + pub metadata: RadrootsProfileEventMetadata, +} + +#[typeshare] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsProfileEventMetadata { + pub id: String, + pub author: String, + pub published_at: u32, + pub profile: RadrootsProfile, +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsProfile { + pub name: String, + pub display_name: Option<String>, + pub nip05: Option<String>, + pub about: Option<String>, + pub website: Option<String>, + pub picture: Option<String>, + pub banner: Option<String>, + pub lud06: Option<String>, + pub lud16: Option<String>, + pub bot: Option<String>, +} diff --git a/src/events/reaction/models.rs b/src/events/reaction/models.rs @@ -0,0 +1,25 @@ +use serde::{Deserialize, Serialize}; +use typeshare::typeshare; +use crate::events::{lib::RadrootsNostrEventRef, RadrootsNostrEvent}; + +#[typeshare] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsReactionEventIndex { + pub event: RadrootsNostrEvent, + pub metadata: RadrootsReactionEventMetadata, +} + +#[typeshare] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsReactionEventMetadata { + pub id: String, + pub author: String, + pub published_at: u32, + pub reaction: RadrootsReaction, +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsReaction { + pub root: RadrootsNostrEventRef, + pub content: String, +} diff --git a/src/lib.rs b/src/lib.rs @@ -3,3 +3,4 @@ pub const KIND_JOB_RESPONSE: u16 = 6300; pub const KIND_APPLICATION_HANDLER: u16 = 31990; pub mod models; +pub mod events; +\ No newline at end of file diff --git a/src/models/events.rs b/src/models/events.rs @@ -1,139 +0,0 @@ -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 RadrootsMetadataEvent { - pub event: RadrootsNostrEvent, - pub data: RadrootsMetadataEventData, -} - -#[typeshare] -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct RadrootsMetadataEventDataMetadata { - pub name: String, - pub display_name: Option<String>, - pub nip05: Option<String>, - pub about: Option<String>, -} - -#[typeshare] -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct RadrootsMetadataEventData { - pub id: String, - pub public_key: String, - pub published_at: u32, - pub metadata: RadrootsMetadataEventDataMetadata, -} - -#[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 RadrootsListingEvent { - pub event: RadrootsNostrEvent, - pub data: RadrootsListingEventData, -} - -#[typeshare] -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct RadrootsListingEventData { - pub id: String, - pub author: String, - 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/listing_order.rs b/src/models/listing_order.rs @@ -1,61 +0,0 @@ -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, - pub count: u32, -} - -#[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 @@ -1,40 +0,0 @@ -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 @@ -1,4 +1 @@ -pub mod events; -pub mod listing_order; -pub mod listing_order_request; -pub mod indexer; -\ No newline at end of file +pub mod indexer;