web_lib

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

lib.ts (1002B)


      1 import { KIND_FARM, type RadrootsFarm, type RadrootsFarmRef } from "@radroots/events-bindings";
      2 import type { NostrEventTags } from "../../types/lib.js";
      3 import type { NostrEventFigure, NostrSignedEvent } from "../../types/nostr.js";
      4 import { nostr_event_create } from "../lib.js";
      5 import { tags_farm } from "./tags.js";
      6 
      7 export const nostr_tags_farm_ref = (farm: RadrootsFarmRef): NostrEventTags | undefined => {
      8     if (!farm.pubkey.trim()) return undefined;
      9     if (!farm.d_tag.trim()) return undefined;
     10     return [
     11         ["p", farm.pubkey],
     12         ["a", `${KIND_FARM}:${farm.pubkey}:${farm.d_tag}`],
     13     ];
     14 };
     15 
     16 export const nostr_event_farm = async (
     17     opts: NostrEventFigure<{ data: RadrootsFarm }>,
     18 ): Promise<NostrSignedEvent | undefined> => {
     19     const { data } = opts;
     20     const tags = await tags_farm(data);
     21     return nostr_event_create({
     22         ...opts,
     23         basis: {
     24             kind: KIND_FARM,
     25             content: JSON.stringify(data),
     26             tags,
     27         },
     28     });
     29 };