diff --git a/packages/client/src/plugins/base.ts b/packages/client/src/plugins/base.ts index 41f601a..5ba3af6 100644 --- a/packages/client/src/plugins/base.ts +++ b/packages/client/src/plugins/base.ts @@ -24,46 +24,6 @@ export const projection = ($: Readable, get = getter($)) => ({$, get}) export const projectFrom = (src: Projection, read: ($: S) => U): Projection => projection(derived(src.$, read), () => read(src.get())) -/** - * Synchronous read access to a keyed collection's current value. Shared by - * collections that own a map (`MapPlugin`) and those that are read-only views - * over the repository (`DerivedPlugin`). - */ -export interface ReadableMap { - get(key: string): Maybe -} - -/** - * Direct get/set access to a keyed collection the plugin owns. Extends the read - * accessors with mutation plus change notification. Only collections that own - * their map implement this — repository-backed collections are read-only. - */ -export interface Mappable extends ReadableMap { - set(key: string, value: T): void - delete(key: string): void - clear(): void - onItem(subscriber: (key: string, value: Maybe) => void): Unsubscriber -} - -/** - * Lazy, async loading of items by key from the network, with per-key caching - * and backoff (`load`) or a cache-bypassing refresh (`forceLoad`). - */ -export interface Loadable { - load(key: string, ...args: any[]): Promise> - forceLoad(key: string, ...args: any[]): Promise> -} - -/** - * Reactive derivations over a keyed collection: the whole map (`index`), its - * values (`all`), and a per-key on-demand store (`one`). - */ -export interface Derivable { - index: Projection> - all: Projection - one(key?: string, ...args: any[]): Readable> -} - /** * Base class for a reactive, keyed collection of "local" (non-event) data — * things like relay stats or NIP-11 profiles that aren't backed by the @@ -73,7 +33,7 @@ export interface Derivable { * snapshot via `.get()`. Per-key access is `one(key)`, a plain on-demand store * (snapshot with svelte's `get(...)`, or read `get(key)` directly). */ -export class MapPlugin implements Mappable, Derivable { +export class MapPlugin { protected store = writable(new Map()) index: Projection> all: Projection @@ -143,7 +103,7 @@ export class MapPlugin implements Mappable, Derivable { * network. Subclasses implement `fetch`; `load`/`forceLoad`/`one` are derived * from it (with per-key caching and backoff via `makeLoadItem`). */ -export abstract class LoadableMapPlugin extends MapPlugin implements Loadable { +export abstract class LoadableMapPlugin extends MapPlugin { load: (key: string, ...args: any[]) => Promise> forceLoad: (key: string, ...args: any[]) => Promise> @@ -181,7 +141,7 @@ export type DerivedPluginOptions = { * `index` (map) and `all` (values) are `Projection`s — subscribe via `.$`, * snapshot via `.get()`. Per-key access is `one(key)`, a plain on-demand store. */ -export abstract class DerivedPlugin implements ReadableMap, Loadable, Derivable { +export abstract class DerivedPlugin { index: Projection> all: Projection one: (key?: string, ...args: any[]) => Readable>