feat(storage): define StorageAdapter interface types + scaffold package
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1
packages/storage/src/index.ts
Normal file
1
packages/storage/src/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export type { StorageAdapter, StorageConfig } from './types.js';
|
||||
43
packages/storage/src/types.ts
Normal file
43
packages/storage/src/types.ts
Normal 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' };
|
||||
Reference in New Issue
Block a user