@snort/system-react package
This commit is contained in:
@ -1,13 +1,13 @@
|
||||
import debug from "debug";
|
||||
|
||||
import { unwrap, sanitizeRelayUrl, ExternalStore } from "@snort/shared";
|
||||
import { unwrap, sanitizeRelayUrl, ExternalStore, FeedCache } from "@snort/shared";
|
||||
import { NostrEvent, TaggedRawEvent } from "./Nostr";
|
||||
import { AuthHandler, Connection, RelaySettings, ConnectionStateSnapshot } from "./Connection";
|
||||
import { Query } from "./Query";
|
||||
import { RelayCache } from "./GossipModel";
|
||||
import { NoteStore } from "./NoteCollection";
|
||||
import { BuiltRawReqFilter, RequestBuilder } from "./RequestBuilder";
|
||||
import { SystemInterface, SystemSnapshot } from ".";
|
||||
import { MetadataCache, ProfileLoaderService, SystemInterface, SystemSnapshot, UserProfileCache, UserRelaysCache } from ".";
|
||||
|
||||
/**
|
||||
* Manages nostr content retrieval system
|
||||
@ -35,13 +35,36 @@ export class NostrSystem extends ExternalStore<SystemSnapshot> implements System
|
||||
*/
|
||||
#relayCache: RelayCache;
|
||||
|
||||
constructor(props: { authHandler?: AuthHandler, relayCache: RelayCache }) {
|
||||
/**
|
||||
* Storage class for user profiles
|
||||
*/
|
||||
#profileCache: FeedCache<MetadataCache>;
|
||||
|
||||
/**
|
||||
* Profile loading service
|
||||
*/
|
||||
#profileLoader: ProfileLoaderService;
|
||||
|
||||
constructor(props: {
|
||||
authHandler?: AuthHandler,
|
||||
relayCache?: RelayCache,
|
||||
profileCache?: FeedCache<MetadataCache>
|
||||
}) {
|
||||
super();
|
||||
this.#handleAuth = props.authHandler;
|
||||
this.#relayCache = props.relayCache;
|
||||
this.#relayCache = props.relayCache ?? new UserRelaysCache();
|
||||
this.#profileCache = props.profileCache ?? new UserProfileCache();
|
||||
this.#profileLoader = new ProfileLoaderService(this, this.#profileCache);
|
||||
this.#cleanup();
|
||||
}
|
||||
|
||||
/**
|
||||
* Profile loader service allows you to request profiles
|
||||
*/
|
||||
get ProfileLoader() {
|
||||
return this.#profileLoader;
|
||||
}
|
||||
|
||||
get Sockets(): ConnectionStateSnapshot[] {
|
||||
return [...this.#sockets.values()].map(a => a.snapshot());
|
||||
}
|
||||
|
@ -22,6 +22,10 @@ export class ProfileLoaderService {
|
||||
this.#FetchMetadata();
|
||||
}
|
||||
|
||||
get Cache() {
|
||||
return this.#cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Request profile metadata for a set of pubkeys
|
||||
*/
|
||||
|
@ -27,7 +27,7 @@ export class SystemWorker extends ExternalStore<SystemSnapshot> implements Syste
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
|
||||
Query<T extends NoteStore>(type: new () => T, req: RequestBuilder | null): Query | undefined {
|
||||
Query<T extends NoteStore>(type: new () => T, req: RequestBuilder | null): Query {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ export interface SystemInterface {
|
||||
HandleAuth?: AuthHandler;
|
||||
get Sockets(): Array<ConnectionStateSnapshot>;
|
||||
GetQuery(id: string): Query | undefined;
|
||||
Query<T extends NoteStore>(type: { new(): T }, req: RequestBuilder | null): Query | undefined;
|
||||
Query<T extends NoteStore>(type: { new(): T }, req: RequestBuilder | null): Query;
|
||||
ConnectToRelay(address: string, options: RelaySettings): Promise<void>;
|
||||
DisconnectRelay(address: string): void;
|
||||
BroadcastEvent(ev: NostrEvent): void;
|
||||
|
Reference in New Issue
Block a user