@yihuangdb/storage-object
Version:
A Node.js storage object layer library using Redis OM
113 lines • 3.43 kB
TypeScript
import { StorageObject, StorageOptions } from './storage';
import { SchemaConfig } from './schema';
import { SchemaMetadata } from './schema-registry';
/**
* Create a new storage instance and register it with the schema registry
*/
export declare function createStorage<T extends Record<string, any> = any>(name: string, schema: SchemaConfig, options?: StorageOptions): Promise<StorageObject<T>>;
/**
* Get an existing storage instance by name only
* The schema will be retrieved from the registry
*/
export declare function getStorage<T extends Record<string, any> = any>(name: string): Promise<StorageObject<T> | null>;
/**
* Get or create a storage instance
* If the storage doesn't exist, it will be created with the provided schema
*/
export declare function getOrCreateStorage<T extends Record<string, any> = any>(name: string, schema?: SchemaConfig, options?: StorageOptions): Promise<StorageObject<T>>;
/**
* List all registered storage schemas
*/
export declare function listStorages(): Promise<SchemaMetadata[]>;
/**
* Get storage metadata including statistics
*/
export declare function getStorageMetadata(name: string): Promise<SchemaMetadata | null>;
/**
* Delete a storage and all its data
*/
export declare function deleteStorage(name: string): Promise<boolean>;
/**
* Validate a storage schema against its data
*/
export declare function validateStorage(name: string): Promise<{
valid: boolean;
errors: string[];
warnings: string[];
}>;
/**
* Get storage statistics
*/
export declare function getStorageStats(name: string): Promise<{
objectCount: number;
totalOperations: number;
averageObjectSize: number;
performance: {
averageCreateTime: number;
averageReadTime: number;
averageUpdateTime: number;
averageDeleteTime: number;
};
} | null>;
/**
* Backup all storages or a specific storage
*/
export declare function backupStorages(options?: {
names?: string[];
includeData?: boolean;
compress?: boolean;
}): Promise<string>;
/**
* Restore storages from backup
*/
export declare function restoreStorages(backupJson: string, options?: {
overwrite?: boolean;
skipExisting?: boolean;
validateSchema?: boolean;
}): Promise<{
success: boolean;
restored: string[];
failed: string[];
errors: Record<string, string>;
}>;
/**
* Clean up inactive storages
*/
export declare function cleanupStorages(inactiveDays?: number): Promise<{
cleaned: string[];
kept: string[];
}>;
/**
* Get global statistics across all storages
*/
export declare function getGlobalStats(): Promise<{
totalSchemas: number;
activeSchemas: number;
totalObjects: number;
totalOperations: number;
storageSize: number;
topSchemas: Array<{
name: string;
operations: number;
objects: number;
}>;
}>;
/**
* Monitor storage changes with a callback
*/
export declare function monitorStorage(name: string, callback: (event: {
type: 'create' | 'update' | 'delete';
entityId?: string;
data?: any;
timestamp: Date;
}) => void): () => void;
/**
* Migrate data from one schema version to another
*/
export declare function migrateStorage(name: string, newSchema: SchemaConfig, transform?: (oldData: any) => any): Promise<{
success: boolean;
migrated: number;
failed: number;
errors: string[];
}>;
//# sourceMappingURL=storage-factory.d.ts.map