Files
plugin-manager/src/interfaces.ts
2026-04-18 20:08:42 +10:00

35 lines
1014 B
TypeScript

/**
* Minimal key-value storage adapter.
* Pass `localStorage` in browser environments, or any Map-backed adapter for Node.js / tests.
*/
export interface IPluginStorage {
getItem(key: string): string | null;
setItem(key: string, value: string): void;
}
/**
* Minimal event emitter interface for the plugin events API.
* Compatible with Node.js EventEmitter, matrix-js-sdk MatrixClient, and similar clients.
*/
export interface IPluginEventClient {
on(event: string, handler: (...args: any[]) => void): void;
off(event: string, handler: (...args: any[]) => void): void;
}
/**
* In-memory storage implementation — used as the default when no storage adapter is provided.
*/
export class MemoryStorage implements IPluginStorage {
private readonly store = new Map<string, string>();
/** @inheritdoc */
getItem(key: string): string | null {
return this.store.get(key) ?? null;
}
/** @inheritdoc */
setItem(key: string, value: string): void {
this.store.set(key, value);
}
}