Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions js/.changeset/storage-backend-interface.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
'links-queue-js': minor
---

Add pluggable StorageBackend interface for switching between storage backends via configuration

- Add `StorageBackend` interface with lifecycle, CRUD, batch, and metadata operations
- Add `BackendCapabilities` and `BackendStats` types for backend introspection
- Add `MemoryBackendAdapter` wrapping `MemoryLinkStore` with `StorageBackend` interface
- Add `BackendRegistry` for registering and creating backends by configuration
- Add comprehensive tests for backend registry and adapter
78 changes: 78 additions & 0 deletions js/src/backends/registry.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* Backend registry type definitions for links-queue.
*/

import type {
StorageBackend,
BackendOptions,
BackendConstructor,
BackendFactory,
BackendCapabilities,
BackendStats,
MemoryBackendOptions,
} from './types.ts';
import type { Link, LinkId, LinkPattern } from '../types.ts';

/**
* Memory backend adapter that wraps MemoryLinkStore with StorageBackend interface.
*/
export declare class MemoryBackendAdapter implements StorageBackend {
constructor(options?: MemoryBackendOptions);

connect(): Promise<void>;
disconnect(): Promise<void>;
isConnected(): boolean;

save(link: Link): Promise<LinkId>;
load(id: LinkId): Promise<Link | null>;
delete(id: LinkId): Promise<boolean>;
query(pattern: LinkPattern): Promise<Link[]>;

saveBatch(links: readonly Link[]): Promise<LinkId[]>;
deleteBatch(ids: readonly LinkId[]): Promise<boolean[]>;

getCapabilities(): BackendCapabilities;
getStats(): BackendStats;

clear(): Promise<void>;
}

/**
* Backend registry interface.
*/
export interface BackendRegistryInterface {
/**
* Registers a backend implementation.
*/
register(name: string, backend: BackendConstructor | BackendFactory): void;

/**
* Unregisters a backend implementation.
*/
unregister(name: string): boolean;

/**
* Checks if a backend is registered.
*/
has(name: string): boolean;

/**
* Creates a backend instance from configuration.
*/
create(config: BackendOptions): StorageBackend;

/**
* Lists all registered backend types.
*/
listTypes(): string[];

/**
* Resets the registry to default state.
*/
reset(): void;
}

/**
* Singleton backend registry instance.
*/
export declare const BackendRegistry: BackendRegistryInterface;
Loading