web_lib

Common web application libraries
git clone https://radroots.dev/git/web_lib.git
Log | Files | Refs | LICENSE

commit bad0798d404bba40617a5407a36c799b4dd711d7
parent 6ecfdab4d5b362bdc8272dcdde6c1776c42b39fe
Author: triesap <triesap@radroots.dev>
Date:   Sat, 27 Dec 2025 18:07:33 +0000

nostr: align event kinds with bindings constants

- Replace hardcoded Radroots kind literals with @radroots/events-bindings exports
- Update parse/event basis typing to reference KIND_* values
- Expand NIP-51 kind arrays to use exported list and list_set kind constants
- Add _env_lib helper and re-export additional apps-lib entrypoints

Diffstat:
Mapps-lib/src/lib/index.ts | 25+++++++++++++++++++++++++
Aapps-lib/src/lib/utils/_env.ts | 17+++++++++++++++++
Mgeocoder/src/geocoder.ts | 3++-
Mnostr/src/events/comment/lib.ts | 7++-----
Mnostr/src/events/comment/parse.ts | 8+++-----
Mnostr/src/events/farm/lib.ts | 9+++------
Mnostr/src/events/farm/parse.ts | 8+++-----
Mnostr/src/events/follow/lib.ts | 7++-----
Mnostr/src/events/follow/parse.ts | 8+++-----
Mnostr/src/events/lib.ts | 3++-
Mnostr/src/events/list/lib.ts | 53++++++++++++++++++++++++++++++++++++-----------------
Mnostr/src/events/list_set/lib.ts | 49+++++++++++++++++++++++++++++++++----------------
Mnostr/src/events/listing/lib.ts | 7++-----
Mnostr/src/events/listing/parse.ts | 16++++++++--------
Mnostr/src/events/plot/lib.ts | 7++-----
Mnostr/src/events/plot/parse.ts | 11++++-------
Mnostr/src/events/profile/lib.ts | 7++-----
Mnostr/src/events/profile/parse.ts | 8+++-----
Mnostr/src/events/reaction/lib.ts | 7++-----
Mnostr/src/events/reaction/parse.ts | 8+++-----
Mnostr/src/events/subscription.ts | 25++++++++++++++++---------
21 files changed, 173 insertions(+), 120 deletions(-)

diff --git a/apps-lib/src/lib/index.ts b/apps-lib/src/lib/index.ts @@ -1,5 +1,30 @@ export * from "./components/index.js"; +export * from "./components/view-context.js"; +export * from "./index.js"; +export * from "./stores/app.js"; +export * from "./stores/carousel.js"; export * from "./stores/index.js"; +export * from "./stores/theme.js"; +export * from "./styles/glyphs.js"; export * from "./styles/index.js"; +export * from "./types/components.js"; export * from "./types/index.js"; +export * from "./types/lib.js"; +export * from "./types/ui.js"; +export * from "./utils/app/carousel.js"; +export * from "./utils/app/index.js"; +export * from "./utils/browser.js"; +export * from "./utils/fetch.js"; +export * from "./utils/geo.js"; +export * from "./utils/i18n.js"; export * from "./utils/index.js"; +export * from "./utils/keyval/idb.js"; +export { default as Fade } from "./components/fade.svelte"; +export { default as Flex } from "./components/flex.svelte"; +export { default as Glyph } from "./components/glyph.svelte"; +export { default as Glyphi } from "./components/glyphi.svelte"; +export { default as ImageBlob } from "./components/image-blob.svelte"; +export { default as ImageSrc } from "./components/image-src.svelte"; +export { default as Input } from "./components/input.svelte"; +export { default as ViewPane } from "./components/view-pane.svelte"; +export { default as ViewStack } from "./components/view-stack.svelte"; diff --git a/apps-lib/src/lib/utils/_env.ts b/apps-lib/src/lib/utils/_env.ts @@ -0,0 +1,17 @@ +const KEYVAL_NAME = import.meta.env.VITE_PUBLIC_KEYVAL_NAME; +if (!KEYVAL_NAME || typeof KEYVAL_NAME !== 'string') throw new Error('Missing env var: VITE_PUBLIC_KEYVAL_NAME'); + +const NOSTR_CLIENT = import.meta.env.VITE_PUBLIC_NOSTR_CLIENT; +if (!NOSTR_CLIENT || typeof NOSTR_CLIENT !== 'string') throw new Error('Missing env var: VITE_PUBLIC_NOSTR_CLIENT'); + +const RADROOTS_RELAY = import.meta.env.VITE_PUBLIC_RADROOTS_RELAY; +if (!RADROOTS_RELAY || typeof RADROOTS_RELAY !== 'string') throw new Error('Missing env var: VITE_PUBLIC_RADROOTS_RELAY'); + +const PROD = import.meta.env.MODE === 'production'; + +export const _env_lib = { + PROD, + KEYVAL_NAME, + NOSTR_CLIENT, + RADROOTS_RELAY, +} as const; diff --git a/geocoder/src/geocoder.ts b/geocoder/src/geocoder.ts @@ -6,6 +6,7 @@ import { parse_geocode_country_center_result, parse_geocode_country_list_result, const KM_PER_DEGREE_LATITUDE = 111; const DEFAULT_SQL_WASM_PATH = `/assets/sql-wasm.wasm`; +const DEFAULT_SQL_DATABASE_PATH = `/assets/geonames.db`; export class Geocoder implements IGeocoder { private _db: Database | null = null; @@ -13,7 +14,7 @@ export class Geocoder implements IGeocoder { constructor(database_name?: string) { if (database_name && database_name.charAt(0) !== `/`) throw new Error(`Error: database name must be a valid path`); - this._database_name = database_name || `/geonames/geonames.db`; + this._database_name = database_name || DEFAULT_SQL_DATABASE_PATH; } public async connect(wasm_path?: string): Promise<IGeocoderConnectResolve> { diff --git a/nostr/src/events/comment/lib.ts b/nostr/src/events/comment/lib.ts @@ -1,11 +1,8 @@ -import type { RadrootsComment } from "@radroots/events-bindings"; +import { KIND_COMMENT, type RadrootsComment } from "@radroots/events-bindings"; import type { NostrEventFigure, NostrSignedEvent } from "../../types/nostr.js"; import { nostr_event_create } from "../lib.js"; import { tags_comment } from "./tags.js"; -export const KIND_RADROOTS_COMMENT = 1111; -export type KindRadrootsComment = typeof KIND_RADROOTS_COMMENT; - export const nostr_event_comment = async ( opts: NostrEventFigure<{ data: RadrootsComment }>, ): Promise<NostrSignedEvent | undefined> => { @@ -14,7 +11,7 @@ export const nostr_event_comment = async ( return nostr_event_create({ ...opts, basis: { - kind: KIND_RADROOTS_COMMENT, + kind: KIND_COMMENT, content: data.content, tags, }, diff --git a/nostr/src/events/comment/parse.ts b/nostr/src/events/comment/parse.ts @@ -1,16 +1,14 @@ -import type { RadrootsComment } from "@radroots/events-bindings"; -import { radroots_comment_schema } from "@radroots/events-bindings"; +import { KIND_COMMENT, radroots_comment_schema, type RadrootsComment } from "@radroots/events-bindings"; import type { NostrEvent } from "../../types/nostr.js"; import { parse_nostr_event_basis } from "../lib.js"; import type { NostrEventBasis } from "../subscription.js"; -import { KIND_RADROOTS_COMMENT, type KindRadrootsComment } from "./lib.js"; -export type RadrootsCommentNostrEvent = NostrEventBasis<KindRadrootsComment> & { comment: RadrootsComment }; +export type RadrootsCommentNostrEvent = NostrEventBasis<typeof KIND_COMMENT> & { comment: RadrootsComment }; export const parse_nostr_comment_event = ( event: NostrEvent, ): RadrootsCommentNostrEvent | undefined => { - const ev = parse_nostr_event_basis(event, KIND_RADROOTS_COMMENT); + const ev = parse_nostr_event_basis(event, KIND_COMMENT); if (!ev) return undefined; try { const parsed = JSON.parse(event.content); diff --git a/nostr/src/events/farm/lib.ts b/nostr/src/events/farm/lib.ts @@ -1,18 +1,15 @@ -import type { RadrootsFarm, RadrootsFarmRef } from "@radroots/events-bindings"; +import { KIND_FARM, type RadrootsFarm, type RadrootsFarmRef } from "@radroots/events-bindings"; import type { NostrEventTags } from "../../types/lib.js"; import type { NostrEventFigure, NostrSignedEvent } from "../../types/nostr.js"; import { nostr_event_create } from "../lib.js"; import { tags_farm } from "./tags.js"; -export const KIND_RADROOTS_FARM = 30340; -export type KindRadrootsFarm = typeof KIND_RADROOTS_FARM; - export const nostr_tags_farm_ref = (farm: RadrootsFarmRef): NostrEventTags | undefined => { if (!farm.pubkey.trim()) return undefined; if (!farm.d_tag.trim()) return undefined; return [ ["p", farm.pubkey], - ["a", `${KIND_RADROOTS_FARM}:${farm.pubkey}:${farm.d_tag}`], + ["a", `${KIND_FARM}:${farm.pubkey}:${farm.d_tag}`], ]; }; @@ -24,7 +21,7 @@ export const nostr_event_farm = async ( return nostr_event_create({ ...opts, basis: { - kind: KIND_RADROOTS_FARM, + kind: KIND_FARM, content: JSON.stringify(data), tags, }, diff --git a/nostr/src/events/farm/parse.ts b/nostr/src/events/farm/parse.ts @@ -1,16 +1,14 @@ -import type { RadrootsFarm } from "@radroots/events-bindings"; -import { radroots_farm_schema } from "@radroots/events-bindings"; +import { KIND_FARM, radroots_farm_schema, type RadrootsFarm } from "@radroots/events-bindings"; import type { NostrEvent } from "../../types/nostr.js"; import { get_event_tag, parse_nostr_event_basis } from "../lib.js"; import type { NostrEventBasis } from "../subscription.js"; -import { KIND_RADROOTS_FARM, type KindRadrootsFarm } from "./lib.js"; -export type RadrootsFarmNostrEvent = NostrEventBasis<KindRadrootsFarm> & { farm: RadrootsFarm }; +export type RadrootsFarmNostrEvent = NostrEventBasis<typeof KIND_FARM> & { farm: RadrootsFarm }; export const parse_nostr_farm_event = ( event: NostrEvent, ): RadrootsFarmNostrEvent | undefined => { - const ev = parse_nostr_event_basis(event, KIND_RADROOTS_FARM); + const ev = parse_nostr_event_basis(event, KIND_FARM); if (!ev) return undefined; const d_tag = get_event_tag(event.tags, "d"); if (!d_tag) return undefined; diff --git a/nostr/src/events/follow/lib.ts b/nostr/src/events/follow/lib.ts @@ -1,11 +1,8 @@ -import type { RadrootsFollow } from "@radroots/events-bindings"; +import { KIND_FOLLOW, type RadrootsFollow } from "@radroots/events-bindings"; import type { NostrEventFigure, NostrSignedEvent } from "../../types/nostr.js"; import { nostr_event_create } from "../lib.js"; import { tags_follow } from "./tags.js"; -export const KIND_RADROOTS_FOLLOW = 3; -export type KindRadrootsFollow = typeof KIND_RADROOTS_FOLLOW; - export const nostr_event_follows = async ( opts: NostrEventFigure<{ data: RadrootsFollow }>, ): Promise<NostrSignedEvent | undefined> => { @@ -14,7 +11,7 @@ export const nostr_event_follows = async ( return nostr_event_create({ ...opts, basis: { - kind: KIND_RADROOTS_FOLLOW, + kind: KIND_FOLLOW, content: "", tags, }, diff --git a/nostr/src/events/follow/parse.ts b/nostr/src/events/follow/parse.ts @@ -1,16 +1,14 @@ -import type { RadrootsFollow } from "@radroots/events-bindings"; -import { radroots_follow_schema } from "@radroots/events-bindings"; +import { KIND_FOLLOW, radroots_follow_schema, type RadrootsFollow } from "@radroots/events-bindings"; import type { NostrEvent } from "../../types/nostr.js"; import { parse_nostr_event_basis } from "../lib.js"; import type { NostrEventBasis } from "../subscription.js"; -import { KIND_RADROOTS_FOLLOW, type KindRadrootsFollow } from "./lib.js"; -export type RadrootsFollowNostrEvent = NostrEventBasis<KindRadrootsFollow> & { follow: RadrootsFollow }; +export type RadrootsFollowNostrEvent = NostrEventBasis<typeof KIND_FOLLOW> & { follow: RadrootsFollow }; export const parse_nostr_follow_event = ( event: NostrEvent, ): RadrootsFollowNostrEvent | undefined => { - const ev = parse_nostr_event_basis(event, KIND_RADROOTS_FOLLOW); + const ev = parse_nostr_event_basis(event, KIND_FOLLOW); if (!ev) return undefined; try { const parsed = JSON.parse(event.content); diff --git a/nostr/src/events/lib.ts b/nostr/src/events/lib.ts @@ -1,6 +1,7 @@ import { schnorr } from "@noble/curves/secp256k1"; import { hexToBytes } from "@noble/hashes/utils"; import { makeEvent } from "@welshman/util"; +import { KIND_POST } from "@radroots/events-bindings"; import { time_now_ms, time_now_s, uuidv4 } from "@radroots/utils"; import { finalizeEvent, @@ -47,7 +48,7 @@ export const nostr_event_sign_attest = (secret_key: string): NostrToolsEvent => return nostr_event_sign({ secret_key, event: { - kind: 1, + kind: KIND_POST, created_at: time_now_s(), tags: [], content: uuidv4(), diff --git a/nostr/src/events/list/lib.ts b/nostr/src/events/list/lib.ts @@ -1,25 +1,44 @@ -import type { RadrootsList, RadrootsListEntry } from "@radroots/events-bindings"; +import { + KIND_LIST_BLOCKED_RELAYS, + KIND_LIST_BOOKMARKS, + KIND_LIST_COMMUNITIES, + KIND_LIST_DM_RELAYS, + KIND_LIST_EMOJIS, + KIND_LIST_GOOD_WIKI_AUTHORS, + KIND_LIST_GOOD_WIKI_RELAYS, + KIND_LIST_INTERESTS, + KIND_LIST_MEDIA_FOLLOWS, + KIND_LIST_MUTE, + KIND_LIST_PINNED_NOTES, + KIND_LIST_PUBLIC_CHATS, + KIND_LIST_READ_WRITE_RELAYS, + KIND_LIST_RELAY_FEEDS, + KIND_LIST_SEARCH_RELAYS, + KIND_LIST_SIMPLE_GROUPS, + type RadrootsList, + type RadrootsListEntry, +} from "@radroots/events-bindings"; import type { NostrEventFigure, NostrSignedEvent } from "../../types/nostr.js"; import { nostr_event_create } from "../lib.js"; import { tags_list } from "./tags.js"; export const NIP51_LIST_KINDS = [ - 10000, - 10001, - 10002, - 10003, - 10004, - 10005, - 10006, - 10007, - 10009, - 10012, - 10015, - 10020, - 10030, - 10050, - 10101, - 10102, + KIND_LIST_MUTE, + KIND_LIST_PINNED_NOTES, + KIND_LIST_READ_WRITE_RELAYS, + KIND_LIST_BOOKMARKS, + KIND_LIST_COMMUNITIES, + KIND_LIST_PUBLIC_CHATS, + KIND_LIST_BLOCKED_RELAYS, + KIND_LIST_SEARCH_RELAYS, + KIND_LIST_SIMPLE_GROUPS, + KIND_LIST_RELAY_FEEDS, + KIND_LIST_INTERESTS, + KIND_LIST_MEDIA_FOLLOWS, + KIND_LIST_EMOJIS, + KIND_LIST_DM_RELAYS, + KIND_LIST_GOOD_WIKI_AUTHORS, + KIND_LIST_GOOD_WIKI_RELAYS, ] as const; export type KindRadrootsList = typeof NIP51_LIST_KINDS[number]; diff --git a/nostr/src/events/list_set/lib.ts b/nostr/src/events/list_set/lib.ts @@ -1,24 +1,41 @@ -import type { RadrootsListSet } from "@radroots/events-bindings"; +import { + KIND_LIST_SET_APP_CURATION, + KIND_LIST_SET_BOOKMARK, + KIND_LIST_SET_CALENDAR, + KIND_LIST_SET_CURATION, + KIND_LIST_SET_EMOJI, + KIND_LIST_SET_FOLLOW, + KIND_LIST_SET_GENERIC, + KIND_LIST_SET_INTEREST, + KIND_LIST_SET_KIND_MUTE, + KIND_LIST_SET_MEDIA_STARTER_PACK, + KIND_LIST_SET_PICTURE, + KIND_LIST_SET_RELEASE_ARTIFACT, + KIND_LIST_SET_RELAY, + KIND_LIST_SET_STARTER_PACK, + KIND_LIST_SET_VIDEO, + type RadrootsListSet, +} from "@radroots/events-bindings"; import type { NostrEventFigure, NostrSignedEvent } from "../../types/nostr.js"; import { nostr_event_create } from "../lib.js"; import { tags_list_set } from "./tags.js"; export const NIP51_LIST_SET_KINDS = [ - 30000, - 30001, - 30002, - 30003, - 30004, - 30005, - 30006, - 30007, - 30015, - 30030, - 30063, - 30267, - 31924, - 39089, - 39092, + KIND_LIST_SET_FOLLOW, + KIND_LIST_SET_GENERIC, + KIND_LIST_SET_RELAY, + KIND_LIST_SET_BOOKMARK, + KIND_LIST_SET_CURATION, + KIND_LIST_SET_VIDEO, + KIND_LIST_SET_PICTURE, + KIND_LIST_SET_KIND_MUTE, + KIND_LIST_SET_INTEREST, + KIND_LIST_SET_EMOJI, + KIND_LIST_SET_RELEASE_ARTIFACT, + KIND_LIST_SET_APP_CURATION, + KIND_LIST_SET_CALENDAR, + KIND_LIST_SET_STARTER_PACK, + KIND_LIST_SET_MEDIA_STARTER_PACK, ] as const; export type KindRadrootsListSet = typeof NIP51_LIST_SET_KINDS[number]; diff --git a/nostr/src/events/listing/lib.ts b/nostr/src/events/listing/lib.ts @@ -1,11 +1,8 @@ -import type { RadrootsListing } from "@radroots/events-bindings"; +import { KIND_LISTING, type RadrootsListing } from "@radroots/events-bindings"; import type { NostrEventFigure, NostrSignedEvent } from "../../types/nostr.js"; import { nostr_event_create } from "../lib.js"; import { tags_listing } from "./tags.js"; -export const KIND_RADROOTS_LISTING = 30402; -export type KindRadrootsListing = typeof KIND_RADROOTS_LISTING; - export const nostr_event_classified = async ( opts: NostrEventFigure<{ data: RadrootsListing }>, ): Promise<NostrSignedEvent | undefined> => { @@ -14,7 +11,7 @@ export const nostr_event_classified = async ( return nostr_event_create({ ...opts, basis: { - kind: KIND_RADROOTS_LISTING, + kind: KIND_LISTING, content: "", tags, }, diff --git a/nostr/src/events/listing/parse.ts b/nostr/src/events/listing/parse.ts @@ -4,11 +4,7 @@ import type { RadrootsCoreQuantityPrice, } from "@radroots/core-bindings"; import { - type RadrootsListing, - type RadrootsListingDiscount, - type RadrootsListingImage, - type RadrootsListingLocation, - type RadrootsListingQuantity, + KIND_LISTING, radroots_listing_discount_schema, radroots_listing_image_schema, radroots_listing_location_schema, @@ -16,13 +12,17 @@ import { radroots_listing_product_schema, radroots_listing_quantity_schema, radroots_listing_schema, + type RadrootsListing, + type RadrootsListingDiscount, + type RadrootsListingImage, + type RadrootsListingLocation, + type RadrootsListingQuantity, } from "@radroots/events-bindings"; import type { NostrEvent } from "../../types/nostr.js"; import { get_event_tag, get_event_tags, parse_nostr_event_basis } from "../lib.js"; import type { NostrEventBasis } from "../subscription.js"; -import { KIND_RADROOTS_LISTING, type KindRadrootsListing } from "./lib.js"; -export type RadrootsListingNostrEvent = NostrEventBasis<KindRadrootsListing> & { listing: RadrootsListing }; +export type RadrootsListingNostrEvent = NostrEventBasis<typeof KIND_LISTING> & { listing: RadrootsListing }; type CoreUnit = RadrootsCoreQuantity["unit"]; type CoreCurrency = RadrootsCoreMoney["currency"]; @@ -163,7 +163,7 @@ const is_listing_image = (value: RadrootsListingImage | undefined): value is Rad export const parse_nostr_listing_event = ( event: NostrEvent, ): RadrootsListingNostrEvent | undefined => { - const ev = parse_nostr_event_basis(event, KIND_RADROOTS_LISTING); + const ev = parse_nostr_event_basis(event, KIND_LISTING); if (!ev) return undefined; try { const tags = event.tags; diff --git a/nostr/src/events/plot/lib.ts b/nostr/src/events/plot/lib.ts @@ -1,11 +1,8 @@ -import type { RadrootsPlot } from "@radroots/events-bindings"; +import { KIND_PLOT, type RadrootsPlot } from "@radroots/events-bindings"; import type { NostrEventFigure, NostrSignedEvent } from "../../types/nostr.js"; import { nostr_event_create } from "../lib.js"; import { tags_plot } from "./tags.js"; -export const KIND_RADROOTS_PLOT = 30350; -export type KindRadrootsPlot = typeof KIND_RADROOTS_PLOT; - export const nostr_event_plot = async ( opts: NostrEventFigure<{ data: RadrootsPlot }>, ): Promise<NostrSignedEvent | undefined> => { @@ -14,7 +11,7 @@ export const nostr_event_plot = async ( return nostr_event_create({ ...opts, basis: { - kind: KIND_RADROOTS_PLOT, + kind: KIND_PLOT, content: JSON.stringify(data), tags, }, diff --git a/nostr/src/events/plot/parse.ts b/nostr/src/events/plot/parse.ts @@ -1,12 +1,9 @@ -import type { RadrootsPlot } from "@radroots/events-bindings"; -import { radroots_plot_schema } from "@radroots/events-bindings"; +import { KIND_FARM, KIND_PLOT, radroots_plot_schema, type RadrootsPlot } from "@radroots/events-bindings"; import type { NostrEvent } from "../../types/nostr.js"; import { get_event_tag, parse_nostr_event_basis } from "../lib.js"; import type { NostrEventBasis } from "../subscription.js"; -import { KIND_RADROOTS_FARM } from "../farm/lib.js"; -import { KIND_RADROOTS_PLOT, type KindRadrootsPlot } from "./lib.js"; -export type RadrootsPlotNostrEvent = NostrEventBasis<KindRadrootsPlot> & { plot: RadrootsPlot }; +export type RadrootsPlotNostrEvent = NostrEventBasis<typeof KIND_PLOT> & { plot: RadrootsPlot }; type PlotFarmRef = { pubkey: string; @@ -17,7 +14,7 @@ const parse_farm_addr = (value: string): PlotFarmRef | undefined => { const parts = value.split(":"); if (parts.length < 3) return undefined; const kind = Number(parts[0]); - if (!Number.isFinite(kind) || kind !== KIND_RADROOTS_FARM) return undefined; + if (!Number.isFinite(kind) || kind !== KIND_FARM) return undefined; const pubkey = parts[1]?.trim() || ""; const d_tag = parts.slice(2).join(":").trim(); if (!pubkey || !d_tag) return undefined; @@ -27,7 +24,7 @@ const parse_farm_addr = (value: string): PlotFarmRef | undefined => { export const parse_nostr_plot_event = ( event: NostrEvent, ): RadrootsPlotNostrEvent | undefined => { - const ev = parse_nostr_event_basis(event, KIND_RADROOTS_PLOT); + const ev = parse_nostr_event_basis(event, KIND_PLOT); if (!ev) return undefined; const d_tag = get_event_tag(event.tags, "d"); if (!d_tag) return undefined; diff --git a/nostr/src/events/profile/lib.ts b/nostr/src/events/profile/lib.ts @@ -1,11 +1,8 @@ -import type { RadrootsProfile, RadrootsProfileType } from "@radroots/events-bindings"; +import { KIND_PROFILE, type RadrootsProfile, type RadrootsProfileType } from "@radroots/events-bindings"; import type { NostrEventFigure, NostrSignedEvent } from "../../types/nostr.js"; import { nostr_event_create } from "../lib.js"; import { tags_profile_type } from "./tags.js"; -export const KIND_RADROOTS_PROFILE = 0; -export type KindRadrootsProfile = typeof KIND_RADROOTS_PROFILE; - export const nostr_event_profile = async ( opts: NostrEventFigure<{ data: RadrootsProfile; profile_type?: RadrootsProfileType }>, ): Promise<NostrSignedEvent | undefined> => { @@ -14,7 +11,7 @@ export const nostr_event_profile = async ( return nostr_event_create({ ...event_opts, basis: { - kind: KIND_RADROOTS_PROFILE, + kind: KIND_PROFILE, content: JSON.stringify(data), tags: tags.length ? tags : undefined, }, diff --git a/nostr/src/events/profile/parse.ts b/nostr/src/events/profile/parse.ts @@ -1,12 +1,10 @@ -import type { RadrootsProfile, RadrootsProfileType } from "@radroots/events-bindings"; -import { radroots_profile_schema } from "@radroots/events-bindings"; +import { KIND_PROFILE, radroots_profile_schema, type RadrootsProfile, type RadrootsProfileType } from "@radroots/events-bindings"; import type { NostrEvent } from "../../types/nostr.js"; import { parse_nostr_event_basis } from "../lib.js"; import type { NostrEventBasis } from "../subscription.js"; -import { KIND_RADROOTS_PROFILE, type KindRadrootsProfile } from "./lib.js"; import { parse_profile_type_tag } from "./tags.js"; -export type RadrootsProfileNostrEvent = NostrEventBasis<KindRadrootsProfile> & { +export type RadrootsProfileNostrEvent = NostrEventBasis<typeof KIND_PROFILE> & { profile: RadrootsProfile; profile_type?: RadrootsProfileType; }; @@ -14,7 +12,7 @@ export type RadrootsProfileNostrEvent = NostrEventBasis<KindRadrootsProfile> & { export const parse_nostr_profile_event = ( event: NostrEvent, ): RadrootsProfileNostrEvent | undefined => { - const ev = parse_nostr_event_basis(event, KIND_RADROOTS_PROFILE); + const ev = parse_nostr_event_basis(event, KIND_PROFILE); if (!ev) return undefined; try { const parsed = JSON.parse(event.content); diff --git a/nostr/src/events/reaction/lib.ts b/nostr/src/events/reaction/lib.ts @@ -1,11 +1,8 @@ -import type { RadrootsReaction } from "@radroots/events-bindings"; +import { KIND_REACTION, type RadrootsReaction } from "@radroots/events-bindings"; import type { NostrEventFigure, NostrSignedEvent } from "../../types/nostr.js"; import { nostr_event_create } from "../lib.js"; import { tags_reaction } from "./tags.js"; -export const KIND_RADROOTS_REACTION = 7; -export type KindRadrootsReaction = typeof KIND_RADROOTS_REACTION; - export const nostr_event_reaction = async ( opts: NostrEventFigure<{ data: RadrootsReaction }>, ): Promise<NostrSignedEvent | undefined> => { @@ -14,7 +11,7 @@ export const nostr_event_reaction = async ( return nostr_event_create({ ...opts, basis: { - kind: KIND_RADROOTS_REACTION, + kind: KIND_REACTION, content: data.content, tags, }, diff --git a/nostr/src/events/reaction/parse.ts b/nostr/src/events/reaction/parse.ts @@ -1,16 +1,14 @@ -import type { RadrootsReaction } from "@radroots/events-bindings"; -import { radroots_reaction_schema } from "@radroots/events-bindings"; +import { KIND_REACTION, radroots_reaction_schema, type RadrootsReaction } from "@radroots/events-bindings"; import type { NostrEvent } from "../../types/nostr.js"; import { parse_nostr_event_basis } from "../lib.js"; import type { NostrEventBasis } from "../subscription.js"; -import { KIND_RADROOTS_REACTION, type KindRadrootsReaction } from "./lib.js"; -export type RadrootsReactionNostrEvent = NostrEventBasis<KindRadrootsReaction> & { reaction: RadrootsReaction }; +export type RadrootsReactionNostrEvent = NostrEventBasis<typeof KIND_REACTION> & { reaction: RadrootsReaction }; export const parse_nostr_reaction_event = ( event: NostrEvent, ): RadrootsReactionNostrEvent | undefined => { - const ev = parse_nostr_event_basis(event, KIND_RADROOTS_REACTION); + const ev = parse_nostr_event_basis(event, KIND_REACTION); if (!ev) return undefined; try { const parsed = JSON.parse(event.content); diff --git a/nostr/src/events/subscription.ts b/nostr/src/events/subscription.ts @@ -1,4 +1,13 @@ import type { NostrEvent } from "../types/nostr.js"; +import { + KIND_COMMENT, + KIND_FARM, + KIND_FOLLOW, + KIND_LISTING, + KIND_PLOT, + KIND_PROFILE, + KIND_REACTION, +} from "@radroots/events-bindings"; import { parse_nostr_comment_event, RadrootsCommentNostrEvent } from "./comment/parse.js"; import { parse_nostr_farm_event, RadrootsFarmNostrEvent } from "./farm/parse.js"; import { parse_nostr_follow_event, RadrootsFollowNostrEvent } from "./follow/parse.js"; @@ -10,8 +19,6 @@ import { is_nip51_list_set_kind } from "./list_set/lib.js"; import { parse_nostr_plot_event, RadrootsPlotNostrEvent } from "./plot/parse.js"; import { parse_nostr_profile_event, RadrootsProfileNostrEvent } from "./profile/parse.js"; import { parse_nostr_reaction_event, RadrootsReactionNostrEvent } from "./reaction/parse.js"; -import { KIND_RADROOTS_FARM } from "./farm/lib.js"; -import { KIND_RADROOTS_PLOT } from "./plot/lib.js"; export type NostrEventBasis<T extends number> = { id: string; @@ -37,13 +44,13 @@ export const nostr_event_on = (event: NostrEvent): NostrEventPayload | undefined if (is_nip51_list_set_kind(event.kind)) return parse_nostr_list_set_event(event); switch (event.kind) { - case 0: return parse_nostr_profile_event(event); - case 30402: return parse_nostr_listing_event(event); - case 1111: return parse_nostr_comment_event(event); - case 7: return parse_nostr_reaction_event(event); - case 3: return parse_nostr_follow_event(event); - case KIND_RADROOTS_FARM: return parse_nostr_farm_event(event); - case KIND_RADROOTS_PLOT: return parse_nostr_plot_event(event); + case KIND_PROFILE: return parse_nostr_profile_event(event); + case KIND_LISTING: return parse_nostr_listing_event(event); + case KIND_COMMENT: return parse_nostr_comment_event(event); + case KIND_REACTION: return parse_nostr_reaction_event(event); + case KIND_FOLLOW: return parse_nostr_follow_event(event); + case KIND_FARM: return parse_nostr_farm_event(event); + case KIND_PLOT: return parse_nostr_plot_event(event); default: return undefined; } };