feat(storage): define StorageAdapter interface types + scaffold package
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
32
packages/storage/package.json
Normal file
32
packages/storage/package.json
Normal 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"
|
||||
]
|
||||
}
|
||||
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' };
|
||||
9
packages/storage/tsconfig.json
Normal file
9
packages/storage/tsconfig.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"rootDir": "src"
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
||||
Reference in New Issue
Block a user