feat: storage abstraction retrofit — adapters for queue, storage, memory (phases 1-4) #365

Merged
jason.woltje merged 19 commits from feat/storage-abstraction into main 2026-04-03 04:40:58 +00:00
4 changed files with 85 additions and 0 deletions
Showing only changes of commit e797676a02 - Show all commits

View File

@@ -0,0 +1,32 @@
{
"name": "@mosaic/storage",
"version": "0.0.2",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
},
"scripts": {
"build": "tsc",
"lint": "eslint src",
"typecheck": "tsc --noEmit",
"test": "vitest run --passWithNoTests"
},
"dependencies": {
"@mosaic/types": "workspace:*"
},
"devDependencies": {
"typescript": "^5.8.0",
"vitest": "^2.0.0"
},
"publishConfig": {
"registry": "https://git.mosaicstack.dev/api/packages/mosaic/npm/",
"access": "public"
},
"files": [
"dist"
]
}

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' };

View File

@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}