lib

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

commit c54006ec7846ed310e397eff065f58a255e3d360
parent c6a2c434c43a1a2ef1742e81751915e2318a163c
Author: triesap <tyson@radroots.org>
Date:   Tue, 18 Nov 2025 03:07:44 +0000

workspace: unify event models into a consolidated public module surface

Diffstat:
MCargo.lock | 1+
MMakefile | 7++++++-
Mevents-codec/src/job/feedback/decode.rs | 8+++-----
Mevents-codec/src/job/feedback/encode.rs | 4++--
Mevents-codec/src/job/request/decode.rs | 2+-
Mevents-codec/src/job/request/encode.rs | 4++--
Mevents-codec/src/job/result/decode.rs | 10+++-------
Mevents-codec/src/job/result/encode.rs | 4++--
Mevents-codec/src/job/traits.rs | 9++++-----
Mevents-codec/src/job/util.rs | 6+++---
Mevents/Cargo.toml | 5++++-
Mevents/bindings/ts/package.json | 5+++--
Mevents/bindings/ts/src/index.ts | 1+
Mevents/bindings/ts/src/types.ts | 390++++++++++++++++++-------------------------------------------------------------
Aevents/build.rs | 13+++++++++++++
Aevents/src/comment.rs | 33+++++++++++++++++++++++++++++++++
Devents/src/comment/models.rs | 28----------------------------
Aevents/src/follow.rs | 42++++++++++++++++++++++++++++++++++++++++++
Devents/src/follow/models.rs | 34----------------------------------
Aevents/src/job.rs | 35+++++++++++++++++++++++++++++++++++
Devents/src/job/feedback/models.rs | 36------------------------------------
Devents/src/job/mod.rs | 41-----------------------------------------
Devents/src/job/request/models.rs | 50--------------------------------------------------
Devents/src/job/result/models.rs | 36------------------------------------
Aevents/src/job_feedback.rs | 45+++++++++++++++++++++++++++++++++++++++++++++
Aevents/src/job_request.rs | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aevents/src/job_result.rs | 45+++++++++++++++++++++++++++++++++++++++++++++
Mevents/src/lib.rs | 54++++++++++++++++++++++--------------------------------
Aevents/src/listing.rs | 158+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Devents/src/listing/models.rs | 110-------------------------------------------------------------------------------
Aevents/src/post.rs | 30++++++++++++++++++++++++++++++
Devents/src/post/models.rs | 25-------------------------
Aevents/src/profile.rs | 48++++++++++++++++++++++++++++++++++++++++++++++++
Devents/src/profile/models.rs | 34----------------------------------
Aevents/src/reaction.rs | 31+++++++++++++++++++++++++++++++
Devents/src/reaction/models.rs | 26--------------------------
Aevents/src/relay_document.rs | 23+++++++++++++++++++++++
Devents/src/relay_document/models.rs | 13-------------
Devents/src/tag.rs | 3---
Aevents/src/tags.rs | 6++++++
Mtrade/src/listing/price_ext.rs | 2+-
Mtrade/src/listing/stage/order.rs | 2+-
Mtrade/src/listing/tags.rs | 2+-
43 files changed, 719 insertions(+), 803 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock @@ -1706,6 +1706,7 @@ dependencies = [ "radroots-core", "serde", "serde_json", + "ts-rs", "typeshare", ] diff --git a/Makefile b/Makefile @@ -1,5 +1,5 @@ .PHONY: all bindings clean help \ - bindings-tangle-schema bindings-types \ + bindings-events bindings-tangle-schema bindings-types \ build build-tangle-sql-wasm SHELL := /bin/bash @@ -7,6 +7,7 @@ SHELL := /bin/bash TS_RS_FEATURE ?= ts-rs BINDINGS_TARGETS := \ + bindings-events \ bindings-tangle-schema \ bindings-types @@ -32,6 +33,10 @@ help: @printf "%s\n" $(BINDINGS_TARGETS) @printf "%s\n" $(BUILD_TARGETS) +bindings-events: + @(cd events && cargo test --features $(TS_RS_FEATURE)) + @(cd events/bindings/ts && yarn build) + bindings-tangle-schema: @(cd tangle-schema && cargo test --features $(TS_RS_FEATURE)) @(cd tangle-schema/bindings/ts && yarn build) diff --git a/events-codec/src/job/feedback/decode.rs b/events-codec/src/job/feedback/decode.rs @@ -1,10 +1,8 @@ use radroots_events::{ RadrootsNostrEvent, RadrootsNostrEventPtr, - job::{ - JobPaymentRequest, - feedback::models::{ - RadrootsJobFeedback, RadrootsJobFeedbackEventIndex, RadrootsJobFeedbackEventMetadata, - }, + job::JobPaymentRequest, + job_feedback::{ + RadrootsJobFeedback, RadrootsJobFeedbackEventIndex, RadrootsJobFeedbackEventMetadata, }, }; diff --git a/events-codec/src/job/feedback/encode.rs b/events-codec/src/job/feedback/encode.rs @@ -1,6 +1,6 @@ -use radroots_events::job::feedback::models::RadrootsJobFeedback; +use radroots_events::job_feedback::RadrootsJobFeedback; -use crate::job::encode::{canonicalize_tags, JobEncodeError, WireEventParts}; +use crate::job::encode::{JobEncodeError, WireEventParts, canonicalize_tags}; use crate::job::util::{feedback_status_tag, push_amount_tag_msat}; pub fn job_feedback_build_tags(fb: &RadrootsJobFeedback) -> Vec<Vec<String>> { diff --git a/events-codec/src/job/request/decode.rs b/events-codec/src/job/request/decode.rs @@ -1,6 +1,6 @@ use radroots_events::{ RadrootsNostrEvent, - job::request::models::{ + job_request::{ RadrootsJobInput, RadrootsJobParam, RadrootsJobRequest, RadrootsJobRequestEventIndex, RadrootsJobRequestEventMetadata, }, diff --git a/events-codec/src/job/request/encode.rs b/events-codec/src/job/request/encode.rs @@ -1,6 +1,6 @@ -use radroots_events::job::request::models::RadrootsJobRequest; +use radroots_events::job_request::RadrootsJobRequest; -use crate::job::encode::{canonicalize_tags, JobEncodeError, WireEventParts}; +use crate::job::encode::{JobEncodeError, WireEventParts, canonicalize_tags}; use crate::job::util::{job_input_type_tag, push_bid_tag_msat}; pub fn job_request_build_tags(req: &RadrootsJobRequest) -> Vec<Vec<String>> { diff --git a/events-codec/src/job/result/decode.rs b/events-codec/src/job/result/decode.rs @@ -1,12 +1,8 @@ use radroots_events::{ RadrootsNostrEvent, RadrootsNostrEventPtr, - job::{ - JobPaymentRequest, - request::models::RadrootsJobInput, - result::models::{ - RadrootsJobResult, RadrootsJobResultEventIndex, RadrootsJobResultEventMetadata, - }, - }, + job::JobPaymentRequest, + job_request::RadrootsJobInput, + job_result::{RadrootsJobResult, RadrootsJobResultEventIndex, RadrootsJobResultEventMetadata}, }; use crate::job::{ diff --git a/events-codec/src/job/result/encode.rs b/events-codec/src/job/result/encode.rs @@ -1,7 +1,7 @@ -use radroots_events::job::result::models::RadrootsJobResult; +use radroots_events::job_result::RadrootsJobResult; use crate::job::encode::{ - assert_no_inputs_when_encrypted, canonicalize_tags, JobEncodeError, WireEventParts, + JobEncodeError, WireEventParts, assert_no_inputs_when_encrypted, canonicalize_tags, }; use crate::job::util::{job_input_type_tag, push_amount_tag_msat}; diff --git a/events-codec/src/job/traits.rs b/events-codec/src/job/traits.rs @@ -3,11 +3,10 @@ extern crate alloc; #[cfg(not(feature = "std"))] use alloc::{string::String, vec::Vec}; - -use radroots_events::job::{ - feedback::models::{RadrootsJobFeedbackEventIndex, RadrootsJobFeedbackEventMetadata}, - request::models::{RadrootsJobRequestEventIndex, RadrootsJobRequestEventMetadata}, - result::models::{RadrootsJobResultEventIndex, RadrootsJobResultEventMetadata}, +use radroots_events::{ + job_feedback::{RadrootsJobFeedbackEventIndex, RadrootsJobFeedbackEventMetadata}, + job_request::{RadrootsJobRequestEventIndex, RadrootsJobRequestEventMetadata}, + job_result::{RadrootsJobResultEventIndex, RadrootsJobResultEventMetadata}, }; use crate::job::{ diff --git a/events-codec/src/job/util.rs b/events-codec/src/job/util.rs @@ -1,6 +1,6 @@ -use radroots_events::job::{ - request::models::{RadrootsJobInput, RadrootsJobParam}, - JobFeedbackStatus, JobInputType, +use radroots_events::{ + job::{JobFeedbackStatus, JobInputType}, + job_request::{RadrootsJobInput, RadrootsJobParam}, }; use crate::job::error::JobParseError; diff --git a/events/Cargo.toml b/events/Cargo.toml @@ -5,16 +5,19 @@ edition.workspace = true authors = ["Radroots Authors"] rust-version.workspace = true license.workspace = true +build = "build.rs" [features] -default = ["std", "serde", "typeshare"] +default = ["std", "serde", "ts-rs", "typeshare"] std = [] serde = ["dep:serde"] +ts-rs = ["dep:ts-rs"] typeshare = ["dep:typeshare"] [dependencies] radroots-core = { workspace = true, default-features = false, features = ["std", "serde", "typeshare"] } serde = { workspace = true, default-features = false, features = ["alloc", "derive"], optional = true } +ts-rs = { workspace = true, optional = true } typeshare = { workspace = true, optional = true } [dev-dependencies] diff --git a/events/bindings/ts/package.json b/events/bindings/ts/package.json @@ -21,8 +21,9 @@ "scripts": { "build:esm": "tsc -p tsconfig.esm.json", "build:cjs": "tsc -p tsconfig.cjs.json", - "build": "npm run clean && npm run build:esm && npm run build:cjs", - "prebuild": "npm run clean", + "build": "npm run build:esm && npm run build:cjs", + "prebuild": "npm run clean && npm run prepend-imports", + "prepend-imports": "bash -c 'f=./src/types.ts; line=\"import type { RadrootsCoreDiscountValue, RadrootsCoreMoney, RadrootsCorePercent, RadrootsCoreQuantity, RadrootsCoreQuantityPrice } from \\\"@radroots/core-bindings\\\";\"; grep -qxF \"$line\" \"$f\" || (echo -e \"$line\\n\\n$(cat $f)\" > \"$f\")'", "clean": "rimraf dist", "dev": "npm run watch", "watch": "tsc -w" diff --git a/events/bindings/ts/src/index.ts b/events/bindings/ts/src/index.ts @@ -1,3 +1,4 @@ export * from "./lib.js" export * from "./schemas.js" export * from "./types.js" + diff --git a/events/bindings/ts/src/types.ts b/events/bindings/ts/src/types.ts @@ -1,301 +1,89 @@ -import { RadrootsCoreDiscountValue, RadrootsCoreMoney, RadrootsCorePercent, RadrootsCoreQuantity, RadrootsCoreQuantityPrice } from "@radroots/core-bindings"; - -/* - Generated by typeshare 1.13.3 -*/ - -export type RadrootsListingPrice = RadrootsCoreQuantityPrice; - -export interface JobPaymentRequest { - amount_sat: number; - bolt11?: string; -} - -export interface RadrootsNostrEventRef { - id: string; - author: string; - kind: number; - d_tag?: string; - relays?: string[]; -} - -export interface RadrootsComment { - root: RadrootsNostrEventRef; - parent: RadrootsNostrEventRef; - content: string; -} - -export interface RadrootsNostrEvent { - id: string; - author: string; - created_at: number; - kind: number; - tags: string[][]; - content: string; - sig: string; -} - -export interface RadrootsCommentEventMetadata { - id: string; - author: string; - published_at: number; - comment: RadrootsComment; -} - -export interface RadrootsCommentEventIndex { - event: RadrootsNostrEvent; - metadata: RadrootsCommentEventMetadata; -} - -export interface RadrootsFollowProfile { - published_at: number; - public_key: string; - relay_url?: string; - contact_name?: string; -} - -export interface RadrootsFollow { - list: RadrootsFollowProfile[]; -} - -export interface RadrootsFollowEventMetadata { - id: string; - author: string; - published_at: number; - follow: RadrootsFollow; -} - -export interface RadrootsFollowEventIndex { - event: RadrootsNostrEvent; - metadata: RadrootsFollowEventMetadata; -} - -export enum JobFeedbackStatus { - PaymentRequired = "payment_required", - Processing = "processing", - Error = "error", - Success = "success", - Partial = "partial", -} - -export interface RadrootsNostrEventPtr { - id: string; - relays?: string; -} - -export interface RadrootsJobFeedback { - kind: number; - status: JobFeedbackStatus; - extra_info?: string; - request_event: RadrootsNostrEventPtr; - customer_pubkey?: string; - payment?: JobPaymentRequest; - content?: string; - encrypted: boolean; -} - -export interface RadrootsJobFeedbackEventMetadata { - id: string; - author: string; - published_at: number; - job_feedback: RadrootsJobFeedback; -} - -export interface RadrootsJobFeedbackEventIndex { - event: RadrootsNostrEvent; - metadata: RadrootsJobFeedbackEventMetadata; -} - -export enum JobInputType { - Url = "url", - Event = "event", - Job = "job", - Text = "text", -} - -export interface RadrootsJobInput { - data: string; - input_type: JobInputType; - relay?: string; - marker?: string; -} - -export interface RadrootsJobParam { - key: string; - value: string; -} - -export interface RadrootsJobRequest { - kind: number; - inputs: RadrootsJobInput[]; - output?: string; - params: RadrootsJobParam[]; - bid_sat?: number; - relays: string[]; - providers: string[]; - topics: string[]; - encrypted: boolean; -} - -export interface RadrootsJobRequestEventMetadata { - id: string; - author: string; - published_at: number; - job_request: RadrootsJobRequest; -} - -export interface RadrootsJobRequestEventIndex { - event: RadrootsNostrEvent; - metadata: RadrootsJobRequestEventMetadata; -} - -export interface RadrootsJobResult { - kind: number; - request_event: RadrootsNostrEventPtr; - request_json?: string; - inputs: RadrootsJobInput[]; - customer_pubkey?: string; - payment?: JobPaymentRequest; - content?: string; - encrypted: boolean; -} - -export interface RadrootsJobResultEventMetadata { - id: string; - author: string; - published_at: number; - job_result: RadrootsJobResult; -} - -export interface RadrootsJobResultEventIndex { - event: RadrootsNostrEvent; - metadata: RadrootsJobResultEventMetadata; -} - -export interface RadrootsListingProduct { - key: string; - title: string; - category: string; - summary?: string; - process?: string; - lot?: string; - location?: string; - profile?: string; - year?: string; -} - -export interface RadrootsListingQuantity { - value: RadrootsCoreQuantity; - label?: string; - count?: number; -} - -export type RadrootsListingDiscount = - | { kind: "quantity", amount: { - ref_quantity: string; - threshold: RadrootsCoreQuantity; - value: RadrootsCoreMoney; -}} - | { kind: "mass", amount: { - threshold: RadrootsCoreQuantity; - value: RadrootsCoreMoney; -}} - | { kind: "subtotal", amount: { - threshold: RadrootsCoreMoney; - value: RadrootsCoreDiscountValue; -}} - | { kind: "total", amount: { - total_min: RadrootsCoreMoney; - value: RadrootsCorePercent; -}}; - -export interface RadrootsListingLocation { - primary: string; - city?: string; - region?: string; - country?: string; - lat?: number; - lng?: number; - geohash?: string; -} - -export interface RadrootsListingImageSize { - w: number; - h: number; -} - -export interface RadrootsListingImage { - url: string; - size?: RadrootsListingImageSize; -} - -export interface RadrootsListing { - d_tag: string; - product: RadrootsListingProduct; - quantities: RadrootsListingQuantity[]; - prices: RadrootsListingPrice[]; - discounts?: RadrootsListingDiscount[]; - location?: RadrootsListingLocation; - images?: RadrootsListingImage[]; -} - -export interface RadrootsListingEventMetadata { - id: string; - author: string; - published_at: number; - listing: RadrootsListing; -} - -export interface RadrootsListingEventIndex { - event: RadrootsNostrEvent; - metadata: RadrootsListingEventMetadata; -} - -export interface RadrootsProfile { - name: string; - display_name?: string; - nip05?: string; - about?: string; - website?: string; - picture?: string; - banner?: string; - lud06?: string; - lud16?: string; - bot?: string; -} - -export interface RadrootsProfileEventMetadata { - id: string; - author: string; - published_at: number; - profile: RadrootsProfile; -} - -export interface RadrootsProfileEventIndex { - event: RadrootsNostrEvent; - metadata: RadrootsProfileEventMetadata; -} - -export interface RadrootsReaction { - root: RadrootsNostrEventRef; - content: string; -} - -export interface RadrootsReactionEventMetadata { - id: string; - author: string; - published_at: number; - reaction: RadrootsReaction; -} - -export interface RadrootsReactionEventIndex { - event: RadrootsNostrEvent; - metadata: RadrootsReactionEventMetadata; -} - -export const KIND_APPLICATION_HANDLER: number = 31990; -export const KIND_JOB_REQUEST_MIN: number = 5000; -export const KIND_JOB_REQUEST_MAX: number = 5999; -export const KIND_JOB_RESULT_MIN: number = 6000; -export const KIND_JOB_RESULT_MAX: number = 6999; -export const KIND_JOB_FEEDBACK: number = 7000; +import type { RadrootsCoreDiscountValue, RadrootsCoreMoney, RadrootsCorePercent, RadrootsCoreQuantity, RadrootsCoreQuantityPrice } from "@radroots/core-bindings"; + +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +export type JobFeedbackStatus = "payment_required" | "processing" | "error" | "success" | "partial"; + +export type JobInputType = "url" | "event" | "job" | "text"; + +export type JobPaymentRequest = { amount_sat: number, bolt11?: string | null, }; + +export type RadrootsComment = { root: RadrootsNostrEventRef, parent: RadrootsNostrEventRef, content: string, }; + +export type RadrootsCommentEventIndex = { event: RadrootsNostrEvent, metadata: RadrootsCommentEventMetadata, }; + +export type RadrootsCommentEventMetadata = { id: string, author: string, published_at: number, kind: number, comment: RadrootsComment, }; + +export type RadrootsFollow = { list: Array<RadrootsFollowProfile>, }; + +export type RadrootsFollowEventIndex = { event: RadrootsNostrEvent, metadata: RadrootsFollowEventMetadata, }; + +export type RadrootsFollowEventMetadata = { id: string, author: string, published_at: number, kind: number, follow: RadrootsFollow, }; + +export type RadrootsFollowProfile = { published_at: number, public_key: string, relay_url?: string | null, contact_name?: string | null, }; + +export type RadrootsJobFeedback = { kind: number, status: JobFeedbackStatus, extra_info?: string | null, request_event: RadrootsNostrEventPtr, customer_pubkey?: string | null, payment?: JobPaymentRequest | null, content?: string | null, encrypted: boolean, }; + +export type RadrootsJobFeedbackEventIndex = { event: RadrootsNostrEvent, metadata: RadrootsJobFeedbackEventMetadata, }; + +export type RadrootsJobFeedbackEventMetadata = { id: string, author: string, published_at: number, kind: number, job_feedback: RadrootsJobFeedback, }; + +export type RadrootsJobInput = { data: string, input_type: JobInputType, relay?: string | null, marker?: string | null, }; + +export type RadrootsJobParam = { key: string, value: string, }; + +export type RadrootsJobRequest = { kind: number, inputs: Array<RadrootsJobInput>, output?: string | null, params: Array<RadrootsJobParam>, bid_sat?: number | null, relays: Array<string>, providers: Array<string>, topics: Array<string>, encrypted: boolean, }; + +export type RadrootsJobRequestEventIndex = { event: RadrootsNostrEvent, metadata: RadrootsJobRequestEventMetadata, }; + +export type RadrootsJobRequestEventMetadata = { id: string, author: string, published_at: number, kind: number, job_request: RadrootsJobRequest, }; + +export type RadrootsJobResult = { kind: number, request_event: RadrootsNostrEventPtr, request_json?: string | null, inputs: Array<RadrootsJobInput>, customer_pubkey?: string | null, payment?: JobPaymentRequest | null, content?: string | null, encrypted: boolean, }; + +export type RadrootsJobResultEventIndex = { event: RadrootsNostrEvent, metadata: RadrootsJobResultEventMetadata, }; + +export type RadrootsJobResultEventMetadata = { id: string, author: string, published_at: number, kind: number, job_result: RadrootsJobResult, }; + +export type RadrootsListing = { d_tag: string, product: RadrootsListingProduct, quantities: Array<RadrootsListingQuantity>, prices: RadrootsCoreQuantityPrice[], discounts?: RadrootsListingDiscount[] | null, location?: RadrootsListingLocation | null, images?: RadrootsListingImage[] | null, }; + +export type RadrootsListingDiscount = { "kind": "quantity", "amount": { ref_quantity: string, threshold: RadrootsCoreQuantity, value: RadrootsCoreMoney, } } | { "kind": "mass", "amount": { threshold: RadrootsCoreQuantity, value: RadrootsCoreMoney, } } | { "kind": "subtotal", "amount": { threshold: RadrootsCoreMoney, value: RadrootsCoreDiscountValue, } } | { "kind": "total", "amount": { total_min: RadrootsCoreMoney, value: RadrootsCorePercent, } }; + +export type RadrootsListingEventIndex = { event: RadrootsNostrEvent, metadata: RadrootsListingEventMetadata, }; + +export type RadrootsListingEventMetadata = { id: string, author: string, published_at: number, kind: number, listing: RadrootsListing, }; + +export type RadrootsListingImage = { url: string, size?: RadrootsListingImageSize | null, }; + +export type RadrootsListingImageSize = { w: number, h: number, }; + +export type RadrootsListingLocation = { primary: string, city?: string | null, region?: string | null, country?: string | null, lat?: number | null, lng?: number | null, geohash?: string | null, }; + +export type RadrootsListingProduct = { key: string, title: string, category: string, summary?: string | null, process?: string | null, lot?: string | null, location?: string | null, profile?: string | null, year?: string | null, }; + +export type RadrootsListingQuantity = { value: RadrootsCoreQuantity, label?: string | null, count?: number | null, }; + +export type RadrootsNostrEvent = { id: string, author: string, created_at: number, kind: number, tags: Array<Array<string>>, content: string, sig: string, }; + +export type RadrootsNostrEventPtr = { id: string, relays?: string | null, }; + +export type RadrootsNostrEventRef = { id: string, author: string, kind: number, d_tag?: string | null, relays?: string[] | null, }; + +export type RadrootsPost = { content: string, }; + +export type RadrootsPostEventIndex = { event: RadrootsNostrEvent, metadata: RadrootsPostEventMetadata, }; + +export type RadrootsPostEventMetadata = { id: string, author: string, published_at: bigint, kind: number, post: RadrootsPost, }; + +export type RadrootsProfile = { name: string, display_name?: string | null, nip05?: string | null, about?: string | null, website?: string | null, picture?: string | null, banner?: string | null, lud06?: string | null, lud16?: string | null, bot?: string | null, }; + +export type RadrootsProfileEventIndex = { event: RadrootsNostrEvent, metadata: RadrootsProfileEventMetadata, }; + +export type RadrootsProfileEventMetadata = { id: string, author: string, published_at: bigint, kind: number, profile: RadrootsProfile, }; + +export type RadrootsReaction = { root: RadrootsNostrEventRef, content: string, }; + +export type RadrootsReactionEventIndex = { event: RadrootsNostrEvent, metadata: RadrootsReactionEventMetadata, }; + +export type RadrootsReactionEventMetadata = { id: string, author: string, published_at: number, kind: number, reaction: RadrootsReaction, }; + +export type RadrootsRelayDocument = { name?: string | null, description?: string | null, pubkey?: string | null, contact?: string | null, supported_nips?: number[] | null, software?: string | null, version?: string | null, }; diff --git a/events/build.rs b/events/build.rs @@ -0,0 +1,13 @@ +use std::{env, fs, path::Path}; + +fn main() { + println!("cargo:rerun-if-changed=build.rs"); + if env::var_os("CARGO_FEATURE_TS_RS").is_some() { + println!("cargo:rustc-env=TS_RS_EXPORT_DIR=./bindings/ts/src"); + let out_dir = Path::new("bindings/ts/src"); + if !out_dir.exists() { + fs::create_dir_all(out_dir).expect("create TS export dir"); + } + println!("cargo:rerun-if-changed=src"); + } +} diff --git a/events/src/comment.rs b/events/src/comment.rs @@ -0,0 +1,33 @@ +use serde::{Deserialize, Serialize}; +#[cfg(feature = "ts-rs")] +use ts_rs::TS; + +use crate::{RadrootsNostrEvent, RadrootsNostrEventRef}; + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsCommentEventIndex { + pub event: RadrootsNostrEvent, + pub metadata: RadrootsCommentEventMetadata, +} + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsCommentEventMetadata { + pub id: String, + pub author: String, + pub published_at: u32, + pub kind: u32, + pub comment: RadrootsComment, +} + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsComment { + pub root: RadrootsNostrEventRef, + pub parent: RadrootsNostrEventRef, + pub content: String, +} diff --git a/events/src/comment/models.rs b/events/src/comment/models.rs @@ -1,28 +0,0 @@ -use serde::{Deserialize, Serialize}; - -use crate::{RadrootsNostrEvent, RadrootsNostrEventRef}; - -#[typeshare::typeshare] -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct RadrootsCommentEventIndex { - pub event: RadrootsNostrEvent, - pub metadata: RadrootsCommentEventMetadata, -} - -#[typeshare::typeshare] -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct RadrootsCommentEventMetadata { - pub id: String, - pub author: String, - pub published_at: u32, - pub kind: u32, - pub comment: RadrootsComment, -} - -#[typeshare::typeshare] -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct RadrootsComment { - pub root: RadrootsNostrEventRef, - pub parent: RadrootsNostrEventRef, - pub content: String, -} diff --git a/events/src/follow.rs b/events/src/follow.rs @@ -0,0 +1,42 @@ +use crate::RadrootsNostrEvent; +use serde::{Deserialize, Serialize}; +#[cfg(feature = "ts-rs")] +use ts_rs::TS; + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsFollowEventIndex { + pub event: RadrootsNostrEvent, + pub metadata: RadrootsFollowEventMetadata, +} + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsFollowEventMetadata { + pub id: String, + pub author: String, + pub published_at: u32, + pub kind: u32, + pub follow: RadrootsFollow, +} + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsFollow { + pub list: Vec<RadrootsFollowProfile>, +} + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsFollowProfile { + pub published_at: u32, + pub public_key: String, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] + pub relay_url: Option<String>, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] + pub contact_name: Option<String>, +} diff --git a/events/src/follow/models.rs b/events/src/follow/models.rs @@ -1,34 +0,0 @@ -use crate::RadrootsNostrEvent; -use serde::{Deserialize, Serialize}; - -#[typeshare::typeshare] -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct RadrootsFollowEventIndex { - pub event: RadrootsNostrEvent, - pub metadata: RadrootsFollowEventMetadata, -} - -#[typeshare::typeshare] -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct RadrootsFollowEventMetadata { - pub id: String, - pub author: String, - pub published_at: u32, - pub kind: u32, - pub follow: RadrootsFollow, -} - -#[typeshare::typeshare] -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct RadrootsFollow { - pub list: Vec<RadrootsFollowProfile>, -} - -#[typeshare::typeshare] -#[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/events/src/job.rs b/events/src/job.rs @@ -0,0 +1,35 @@ +use serde::{Deserialize, Serialize}; +#[cfg(feature = "ts-rs")] +use ts_rs::TS; + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Copy)] +#[serde(rename_all = "snake_case")] +pub enum JobInputType { + Url, + Event, + Job, + Text, +} + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Copy)] +#[serde(rename_all = "snake_case")] +pub enum JobFeedbackStatus { + PaymentRequired, + Processing, + Error, + Success, + Partial, +} + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] +pub struct JobPaymentRequest { + pub amount_sat: u32, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] + pub bolt11: Option<String>, +} diff --git a/events/src/job/feedback/models.rs b/events/src/job/feedback/models.rs @@ -1,36 +0,0 @@ -use serde::{Deserialize, Serialize}; - -use crate::{ - RadrootsNostrEvent, RadrootsNostrEventPtr, - job::{JobFeedbackStatus, JobPaymentRequest}, -}; - -#[typeshare::typeshare] -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct RadrootsJobFeedbackEventIndex { - pub event: RadrootsNostrEvent, - pub metadata: RadrootsJobFeedbackEventMetadata, -} - -#[typeshare::typeshare] -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct RadrootsJobFeedbackEventMetadata { - pub id: String, - pub author: String, - pub published_at: u32, - pub kind: u32, - pub job_feedback: RadrootsJobFeedback, -} - -#[typeshare::typeshare] -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] -pub struct RadrootsJobFeedback { - pub kind: u16, - pub status: JobFeedbackStatus, - pub extra_info: Option<String>, - pub request_event: RadrootsNostrEventPtr, - pub customer_pubkey: Option<String>, - pub payment: Option<JobPaymentRequest>, - pub content: Option<String>, - pub encrypted: bool, -} diff --git a/events/src/job/mod.rs b/events/src/job/mod.rs @@ -1,41 +0,0 @@ -pub mod feedback { - pub mod models; -} - -pub mod request { - pub mod models; -} - -pub mod result { - pub mod models; -} - -use serde::{Deserialize, Serialize}; - -#[typeshare::typeshare] -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Copy)] -#[serde(rename_all = "snake_case")] -pub enum JobInputType { - Url, - Event, - Job, - Text, -} - -#[typeshare::typeshare] -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Copy)] -#[serde(rename_all = "snake_case")] -pub enum JobFeedbackStatus { - PaymentRequired, - Processing, - Error, - Success, - Partial, -} - -#[typeshare::typeshare] -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] -pub struct JobPaymentRequest { - pub amount_sat: u32, - pub bolt11: Option<String>, -} diff --git a/events/src/job/request/models.rs b/events/src/job/request/models.rs @@ -1,50 +0,0 @@ -use serde::{Deserialize, Serialize}; - -use crate::{RadrootsNostrEvent, job::JobInputType}; - -#[typeshare::typeshare] -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct RadrootsJobRequestEventIndex { - pub event: RadrootsNostrEvent, - pub metadata: RadrootsJobRequestEventMetadata, -} - -#[typeshare::typeshare] -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct RadrootsJobRequestEventMetadata { - pub id: String, - pub author: String, - pub published_at: u32, - pub kind: u32, - pub job_request: RadrootsJobRequest, -} - -#[typeshare::typeshare] -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] -pub struct RadrootsJobInput { - pub data: String, - pub input_type: JobInputType, - pub relay: Option<String>, - pub marker: Option<String>, -} - -#[typeshare::typeshare] -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] -pub struct RadrootsJobParam { - pub key: String, - pub value: String, -} - -#[typeshare::typeshare] -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] -pub struct RadrootsJobRequest { - pub kind: u16, - pub inputs: Vec<RadrootsJobInput>, - pub output: Option<String>, - pub params: Vec<RadrootsJobParam>, - pub bid_sat: Option<u32>, - pub relays: Vec<String>, - pub providers: Vec<String>, - pub topics: Vec<String>, - pub encrypted: bool, -} diff --git a/events/src/job/result/models.rs b/events/src/job/result/models.rs @@ -1,36 +0,0 @@ -use serde::{Deserialize, Serialize}; - -use crate::{ - RadrootsNostrEvent, RadrootsNostrEventPtr, - job::{JobPaymentRequest, request::models::RadrootsJobInput}, -}; - -#[typeshare::typeshare] -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct RadrootsJobResultEventIndex { - pub event: RadrootsNostrEvent, - pub metadata: RadrootsJobResultEventMetadata, -} - -#[typeshare::typeshare] -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct RadrootsJobResultEventMetadata { - pub id: String, - pub author: String, - pub published_at: u32, - pub kind: u32, - pub job_result: RadrootsJobResult, -} - -#[typeshare::typeshare] -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] -pub struct RadrootsJobResult { - pub kind: u16, - pub request_event: RadrootsNostrEventPtr, - pub request_json: Option<String>, - pub inputs: Vec<RadrootsJobInput>, - pub customer_pubkey: Option<String>, - pub payment: Option<JobPaymentRequest>, - pub content: Option<String>, - pub encrypted: bool, -} diff --git a/events/src/job_feedback.rs b/events/src/job_feedback.rs @@ -0,0 +1,45 @@ +use serde::{Deserialize, Serialize}; +#[cfg(feature = "ts-rs")] +use ts_rs::TS; + +use crate::{ + RadrootsNostrEvent, RadrootsNostrEventPtr, + job::{JobFeedbackStatus, JobPaymentRequest}, +}; + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsJobFeedbackEventIndex { + pub event: RadrootsNostrEvent, + pub metadata: RadrootsJobFeedbackEventMetadata, +} + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsJobFeedbackEventMetadata { + pub id: String, + pub author: String, + pub published_at: u32, + pub kind: u32, + pub job_feedback: RadrootsJobFeedback, +} + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] +pub struct RadrootsJobFeedback { + pub kind: u16, + pub status: JobFeedbackStatus, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] + pub extra_info: Option<String>, + pub request_event: RadrootsNostrEventPtr, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] + pub customer_pubkey: Option<String>, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "JobPaymentRequest | null"))] + pub payment: Option<JobPaymentRequest>, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] + pub content: Option<String>, + pub encrypted: bool, +} diff --git a/events/src/job_request.rs b/events/src/job_request.rs @@ -0,0 +1,61 @@ +use serde::{Deserialize, Serialize}; +#[cfg(feature = "ts-rs")] +use ts_rs::TS; + +use crate::{RadrootsNostrEvent, job::JobInputType}; + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsJobRequestEventIndex { + pub event: RadrootsNostrEvent, + pub metadata: RadrootsJobRequestEventMetadata, +} + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsJobRequestEventMetadata { + pub id: String, + pub author: String, + pub published_at: u32, + pub kind: u32, + pub job_request: RadrootsJobRequest, +} + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] +pub struct RadrootsJobInput { + pub data: String, + pub input_type: JobInputType, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] + pub relay: Option<String>, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] + pub marker: Option<String>, +} + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] +pub struct RadrootsJobParam { + pub key: String, + pub value: String, +} + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] +pub struct RadrootsJobRequest { + pub kind: u16, + pub inputs: Vec<RadrootsJobInput>, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] + pub output: Option<String>, + pub params: Vec<RadrootsJobParam>, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "number | null"))] + pub bid_sat: Option<u32>, + pub relays: Vec<String>, + pub providers: Vec<String>, + pub topics: Vec<String>, + pub encrypted: bool, +} diff --git a/events/src/job_result.rs b/events/src/job_result.rs @@ -0,0 +1,45 @@ +use serde::{Deserialize, Serialize}; +#[cfg(feature = "ts-rs")] +use ts_rs::TS; + +use crate::{ + RadrootsNostrEvent, RadrootsNostrEventPtr, job::JobPaymentRequest, + job_request::RadrootsJobInput, +}; + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsJobResultEventIndex { + pub event: RadrootsNostrEvent, + pub metadata: RadrootsJobResultEventMetadata, +} + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsJobResultEventMetadata { + pub id: String, + pub author: String, + pub published_at: u32, + pub kind: u32, + pub job_result: RadrootsJobResult, +} + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] +pub struct RadrootsJobResult { + pub kind: u16, + pub request_event: RadrootsNostrEventPtr, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] + pub request_json: Option<String>, + pub inputs: Vec<RadrootsJobInput>, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] + pub customer_pubkey: Option<String>, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "JobPaymentRequest | null"))] + pub payment: Option<JobPaymentRequest>, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] + pub content: Option<String>, + pub encrypted: bool, +} diff --git a/events/src/lib.rs b/events/src/lib.rs @@ -1,38 +1,23 @@ +pub mod comment; +pub mod follow; pub mod job; +pub mod job_feedback; +pub mod job_request; +pub mod job_result; pub mod kinds; -pub mod tag; - -pub mod comment { - pub mod models; -} - -pub mod follow { - pub mod models; -} - -pub mod listing { - pub mod models; -} - -pub mod post { - pub mod models; -} - -pub mod profile { - pub mod models; -} - -pub mod reaction { - pub mod models; -} - -pub mod relay_document { - pub mod models; -} +pub mod listing; +pub mod post; +pub mod profile; +pub mod reaction; +pub mod relay_document; +pub mod tags; use serde::{Deserialize, Serialize}; +#[cfg(feature = "ts-rs")] +use ts_rs::TS; -#[typeshare::typeshare] +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[derive(Clone, Debug, Serialize, Deserialize)] pub struct RadrootsNostrEvent { pub id: String, @@ -44,19 +29,24 @@ pub struct RadrootsNostrEvent { pub sig: String, } -#[typeshare::typeshare] +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[derive(Clone, Debug, Serialize, Deserialize)] pub struct RadrootsNostrEventRef { pub id: String, pub author: String, pub kind: u32, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] pub d_tag: Option<String>, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string[] | null"))] pub relays: Option<Vec<String>>, } -#[typeshare::typeshare] +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] pub struct RadrootsNostrEventPtr { pub id: String, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] pub relays: Option<String>, } diff --git a/events/src/listing.rs b/events/src/listing.rs @@ -0,0 +1,158 @@ +use radroots_core::{ + RadrootsCoreDiscountValue, RadrootsCoreMoney, RadrootsCorePercent, RadrootsCoreQuantity, + RadrootsCoreQuantityPrice, +}; +use serde::{Deserialize, Serialize}; +#[cfg(feature = "ts-rs")] +use ts_rs::TS; + +use crate::RadrootsNostrEvent; + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsListingEventIndex { + pub event: RadrootsNostrEvent, + pub metadata: RadrootsListingEventMetadata, +} + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsListingEventMetadata { + pub id: String, + pub author: String, + pub published_at: u32, + pub kind: u32, + pub listing: RadrootsListing, +} + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsListing { + pub d_tag: String, + pub product: RadrootsListingProduct, + pub quantities: Vec<RadrootsListingQuantity>, + #[cfg_attr(feature = "ts-rs", ts(type = "RadrootsCoreQuantityPrice[]"))] + pub prices: Vec<RadrootsCoreQuantityPrice>, + #[cfg_attr( + feature = "ts-rs", + ts(optional, type = "RadrootsListingDiscount[] | null") + )] + pub discounts: Option<Vec<RadrootsListingDiscount>>, + #[cfg_attr( + feature = "ts-rs", + ts(optional, type = "RadrootsListingLocation | null") + )] + pub location: Option<RadrootsListingLocation>, + #[cfg_attr( + feature = "ts-rs", + ts(optional, type = "RadrootsListingImage[] | null") + )] + pub images: Option<Vec<RadrootsListingImage>>, +} + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsListingProduct { + pub key: String, + pub title: String, + pub category: String, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] + pub summary: Option<String>, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] + pub process: Option<String>, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] + pub lot: Option<String>, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] + pub location: Option<String>, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] + pub profile: Option<String>, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] + pub year: Option<String>, +} + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsListingQuantity { + #[cfg_attr(feature = "ts-rs", ts(type = "RadrootsCoreQuantity"))] + pub value: RadrootsCoreQuantity, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] + pub label: Option<String>, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "number | null"))] + pub count: Option<u32>, +} + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Debug, Serialize, Deserialize)] +#[serde(rename_all = "snake_case", tag = "kind", content = "amount")] +pub enum RadrootsListingDiscount { + Quantity { + ref_quantity: String, + #[cfg_attr(feature = "ts-rs", ts(type = "RadrootsCoreQuantity"))] + threshold: RadrootsCoreQuantity, + #[cfg_attr(feature = "ts-rs", ts(type = "RadrootsCoreMoney"))] + value: RadrootsCoreMoney, + }, + Mass { + #[cfg_attr(feature = "ts-rs", ts(type = "RadrootsCoreQuantity"))] + threshold: RadrootsCoreQuantity, + #[cfg_attr(feature = "ts-rs", ts(type = "RadrootsCoreMoney"))] + value: RadrootsCoreMoney, + }, + Subtotal { + #[cfg_attr(feature = "ts-rs", ts(type = "RadrootsCoreMoney"))] + threshold: RadrootsCoreMoney, + #[cfg_attr(feature = "ts-rs", ts(type = "RadrootsCoreDiscountValue"))] + value: RadrootsCoreDiscountValue, + }, + Total { + #[cfg_attr(feature = "ts-rs", ts(type = "RadrootsCoreMoney"))] + total_min: RadrootsCoreMoney, + #[cfg_attr(feature = "ts-rs", ts(type = "RadrootsCorePercent"))] + value: RadrootsCorePercent, + }, +} + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsListingLocation { + pub primary: String, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] + pub city: Option<String>, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] + pub region: Option<String>, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] + pub country: Option<String>, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "number | null"))] + pub lat: Option<f64>, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "number | null"))] + pub lng: Option<f64>, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] + pub geohash: Option<String>, +} + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsListingImage { + pub url: String, + #[cfg_attr( + feature = "ts-rs", + ts(optional, type = "RadrootsListingImageSize | null") + )] + pub size: Option<RadrootsListingImageSize>, +} + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsListingImageSize { + pub w: u32, + pub h: u32, +} diff --git a/events/src/listing/models.rs b/events/src/listing/models.rs @@ -1,110 +0,0 @@ -use radroots_core::{ - RadrootsCoreDiscountValue, RadrootsCoreMoney, RadrootsCorePercent, RadrootsCoreQuantity, - RadrootsCoreQuantityPrice, -}; -use serde::{Deserialize, Serialize}; - -use crate::RadrootsNostrEvent; - -#[typeshare::typeshare] -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct RadrootsListingEventIndex { - pub event: RadrootsNostrEvent, - pub metadata: RadrootsListingEventMetadata, -} - -#[typeshare::typeshare] -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct RadrootsListingEventMetadata { - pub id: String, - pub author: String, - pub published_at: u32, - pub kind: u32, - pub listing: RadrootsListing, -} - -#[typeshare::typeshare] -#[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>>, -} - -#[typeshare::typeshare] -#[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>, -} - -#[typeshare::typeshare] -pub type RadrootsListingPrice = RadrootsCoreQuantityPrice; - -#[typeshare::typeshare] -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct RadrootsListingQuantity { - pub value: RadrootsCoreQuantity, - pub label: Option<String>, - pub count: Option<u32>, -} - -#[typeshare::typeshare] -#[derive(Clone, Debug, Serialize, Deserialize)] -#[serde(rename_all = "snake_case", tag = "kind", content = "amount")] -pub enum RadrootsListingDiscount { - Quantity { - ref_quantity: String, - threshold: RadrootsCoreQuantity, - value: RadrootsCoreMoney, - }, - Mass { - threshold: RadrootsCoreQuantity, - value: RadrootsCoreMoney, - }, - Subtotal { - threshold: RadrootsCoreMoney, - value: RadrootsCoreDiscountValue, - }, - Total { - total_min: RadrootsCoreMoney, - value: RadrootsCorePercent, - }, -} - -#[typeshare::typeshare] -#[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>, -} - -#[typeshare::typeshare] -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct RadrootsListingImage { - pub url: String, - pub size: Option<RadrootsListingImageSize>, -} - -#[typeshare::typeshare] -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct RadrootsListingImageSize { - pub w: u32, - pub h: u32, -} diff --git a/events/src/post.rs b/events/src/post.rs @@ -0,0 +1,30 @@ +use crate::RadrootsNostrEvent; +use serde::{Deserialize, Serialize}; +#[cfg(feature = "ts-rs")] +use ts_rs::TS; + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsPostEventIndex { + pub event: RadrootsNostrEvent, + pub metadata: RadrootsPostEventMetadata, +} + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsPostEventMetadata { + pub id: String, + pub author: String, + pub published_at: u64, + pub kind: u32, + pub post: RadrootsPost, +} + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsPost { + pub content: String, +} diff --git a/events/src/post/models.rs b/events/src/post/models.rs @@ -1,25 +0,0 @@ -use crate::RadrootsNostrEvent; -use serde::{Deserialize, Serialize}; - -#[typeshare::typeshare] -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct RadrootsPostEventIndex { - pub event: RadrootsNostrEvent, - pub metadata: RadrootsPostEventMetadata, -} - -#[typeshare::typeshare] -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct RadrootsPostEventMetadata { - pub id: String, - pub author: String, - pub published_at: u64, - pub kind: u32, - pub post: RadrootsPost, -} - -#[typeshare::typeshare] -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct RadrootsPost { - pub content: String, -} diff --git a/events/src/profile.rs b/events/src/profile.rs @@ -0,0 +1,48 @@ +use crate::RadrootsNostrEvent; +use serde::{Deserialize, Serialize}; +#[cfg(feature = "ts-rs")] +use ts_rs::TS; + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsProfileEventIndex { + pub event: RadrootsNostrEvent, + pub metadata: RadrootsProfileEventMetadata, +} + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsProfileEventMetadata { + pub id: String, + pub author: String, + pub published_at: u64, + pub kind: u32, + pub profile: RadrootsProfile, +} + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsProfile { + pub name: String, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] + pub display_name: Option<String>, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] + pub nip05: Option<String>, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] + pub about: Option<String>, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] + pub website: Option<String>, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] + pub picture: Option<String>, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] + pub banner: Option<String>, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] + pub lud06: Option<String>, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] + pub lud16: Option<String>, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] + pub bot: Option<String>, +} diff --git a/events/src/profile/models.rs b/events/src/profile/models.rs @@ -1,34 +0,0 @@ -use crate::RadrootsNostrEvent; -use serde::{Deserialize, Serialize}; - -#[typeshare::typeshare] -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct RadrootsProfileEventIndex { - pub event: RadrootsNostrEvent, - pub metadata: RadrootsProfileEventMetadata, -} - -#[typeshare::typeshare] -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct RadrootsProfileEventMetadata { - pub id: String, - pub author: String, - pub published_at: u64, - pub kind: u32, - pub profile: RadrootsProfile, -} - -#[typeshare::typeshare] -#[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/events/src/reaction.rs b/events/src/reaction.rs @@ -0,0 +1,31 @@ +use crate::{RadrootsNostrEvent, RadrootsNostrEventRef}; +use serde::{Deserialize, Serialize}; +#[cfg(feature = "ts-rs")] +use ts_rs::TS; + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsReactionEventIndex { + pub event: RadrootsNostrEvent, + pub metadata: RadrootsReactionEventMetadata, +} + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsReactionEventMetadata { + pub id: String, + pub author: String, + pub published_at: u32, + pub kind: u32, + pub reaction: RadrootsReaction, +} + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsReaction { + pub root: RadrootsNostrEventRef, + pub content: String, +} diff --git a/events/src/reaction/models.rs b/events/src/reaction/models.rs @@ -1,26 +0,0 @@ -use crate::{RadrootsNostrEvent, RadrootsNostrEventRef}; -use serde::{Deserialize, Serialize}; - -#[typeshare::typeshare] -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct RadrootsReactionEventIndex { - pub event: RadrootsNostrEvent, - pub metadata: RadrootsReactionEventMetadata, -} - -#[typeshare::typeshare] -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct RadrootsReactionEventMetadata { - pub id: String, - pub author: String, - pub published_at: u32, - pub kind: u32, - pub reaction: RadrootsReaction, -} - -#[typeshare::typeshare] -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct RadrootsReaction { - pub root: RadrootsNostrEventRef, - pub content: String, -} diff --git a/events/src/relay_document.rs b/events/src/relay_document.rs @@ -0,0 +1,23 @@ +use serde::{Deserialize, Serialize}; +#[cfg(feature = "ts-rs")] +use ts_rs::TS; + +#[cfg_attr(feature = "ts-rs", derive(TS))] +#[cfg_attr(feature = "ts-rs", ts(export, export_to = "types.ts"))] +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct RadrootsRelayDocument { + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] + name: Option<String>, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] + description: Option<String>, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] + pubkey: Option<String>, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] + contact: Option<String>, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "number[] | null"))] + supported_nips: Option<Vec<u16>>, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] + software: Option<String>, + #[cfg_attr(feature = "ts-rs", ts(optional, type = "string | null"))] + version: Option<String>, +} diff --git a/events/src/relay_document/models.rs b/events/src/relay_document/models.rs @@ -1,13 +0,0 @@ -use serde::{Deserialize, Serialize}; - -#[typeshare::typeshare] -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct RadrootsRelayDocument { - name: Option<String>, - description: Option<String>, - pubkey: Option<String>, - contact: Option<String>, - supported_nips: Option<Vec<u16>>, - software: Option<String>, - version: Option<String>, -} diff --git a/events/src/tag.rs b/events/src/tag.rs @@ -1,3 +0,0 @@ -pub const TAG_E_ROOT: &str = "e_root"; -pub const TAG_E_PREV: &str = "e_prev"; -pub const TAG_D: &str = "d"; diff --git a/events/src/tags.rs b/events/src/tags.rs @@ -0,0 +1,6 @@ +#[typeshare::typeshare] +pub const TAG_E_ROOT: &str = "e_root"; +#[typeshare::typeshare] +pub const TAG_E_PREV: &str = "e_prev"; +#[typeshare::typeshare] +pub const TAG_D: &str = "d"; diff --git a/trade/src/listing/price_ext.rs b/trade/src/listing/price_ext.rs @@ -3,7 +3,7 @@ use radroots_core::{ RadrootsCoreDecimal, RadrootsCoreQuantity, RadrootsCoreQuantityPrice, RadrootsCoreQuantityPriceOps, }; -use radroots_events::listing::models::RadrootsListingQuantity; +use radroots_events::listing::RadrootsListingQuantity; pub trait AsCoreQuantityPrice { fn as_core_qp(&self) -> RadrootsCoreQuantityPrice; diff --git a/trade/src/listing/stage/order.rs b/trade/src/listing/stage/order.rs @@ -1,7 +1,7 @@ #[cfg(not(feature = "std"))] use alloc::{string::String, vec::Vec}; use radroots_core::RadrootsCoreQuantityPrice; -use radroots_events::listing::models::{RadrootsListingDiscount, RadrootsListingQuantity}; +use radroots_events::listing::{RadrootsListingDiscount, RadrootsListingQuantity}; use crate::listing::model::{RadrootsTradeListingSubtotal, RadrootsTradeListingTotal}; diff --git a/trade/src/listing/tags.rs b/trade/src/listing/tags.rs @@ -1,7 +1,7 @@ #[cfg(not(feature = "std"))] use alloc::{string::String, vec::Vec}; -use radroots_events::tag::{TAG_D, TAG_E_PREV, TAG_E_ROOT}; +use radroots_events::tags::{TAG_D, TAG_E_PREV, TAG_E_ROOT}; use radroots_events_codec::job::error::JobParseError; #[inline]