feat(storage): define StorageAdapter interface types + scaffold package

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Jarvis
2026-04-02 20:22:55 -05:00
parent 05d61e62be
commit e797676a02
4 changed files with 85 additions and 0 deletions

View File

@@ -0,0 +1 @@
export type { StorageAdapter, StorageConfig } from './types.js';

View File

@@ -0,0 +1,43 @@
export interface StorageAdapter {
readonly name: string;
create<T extends Record<string, unknown>>(
collection: string,
data: T,
): Promise<T & { id: string }>;
read<T extends Record<string, unknown>>(collection: string, id: string): Promise<T | null>;
update(collection: string, id: string, data: Record<string, unknown>): Promise<boolean>;
delete(collection: string, id: string): Promise<boolean>;
find<T extends Record<string, unknown>>(
collection: string,
filter?: Record<string, unknown>,
opts?: {
limit?: number;
offset?: number;
orderBy?: string;
order?: 'asc' | 'desc';
},
): Promise<T[]>;
findOne<T extends Record<string, unknown>>(
collection: string,
filter: Record<string, unknown>,
): Promise<T | null>;
count(collection: string, filter?: Record<string, unknown>): Promise<number>;
transaction<T>(fn: (tx: StorageAdapter) => Promise<T>): Promise<T>;
migrate(): Promise<void>;
close(): Promise<void>;
}
export type StorageConfig =
| { type: 'postgres'; url: string }
| { type: 'sqlite'; path: string }
| { type: 'files'; dataDir: string; format?: 'json' | 'md' };