web_lib

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

repository.ts (1412B)


      1 import { Pool, Repository, Tracker } from "@welshman/net";
      2 import type { TrustedEvent } from "@welshman/util";
      3 import type { NostrContext } from "./types/nostr.js";
      4 
      5 export type NostrContextOptions = {
      6     pool?: Pool;
      7     repository?: Repository;
      8     tracker?: Tracker;
      9 };
     10 
     11 export const nostr_pool_create = (): Pool => {
     12     return new Pool();
     13 };
     14 
     15 export const nostr_pool_get = (): Pool => {
     16     return Pool.get();
     17 };
     18 
     19 export const nostr_repository_create = (): Repository => {
     20     return new Repository();
     21 };
     22 
     23 export const nostr_repository_get = (): Repository => {
     24     return Repository.get();
     25 };
     26 
     27 export const nostr_tracker_create = (): Tracker => {
     28     return new Tracker();
     29 };
     30 
     31 export const nostr_context_create = (opts?: NostrContextOptions): NostrContext => {
     32     return {
     33         pool: opts?.pool ?? nostr_pool_create(),
     34         repository: opts?.repository ?? nostr_repository_create(),
     35         tracker: opts?.tracker ?? nostr_tracker_create(),
     36     };
     37 };
     38 
     39 export const nostr_context_default = (): NostrContext => {
     40     return {
     41         pool: nostr_pool_get(),
     42         repository: nostr_repository_get(),
     43         tracker: nostr_tracker_create(),
     44     };
     45 };
     46 
     47 export const nostr_repository_dump = (repository: Repository): TrustedEvent[] => {
     48     return repository.dump();
     49 };
     50 
     51 export const nostr_repository_load = (repository: Repository, events: TrustedEvent[]): void => {
     52     repository.load(events);
     53 };