@sidekick-coder/db
Version:
Cli Tool to manipulate data from diferent sources
56 lines (53 loc) • 2.48 kB
text/typescript
import { FilesystemOptions, FilesystemOptionsPath, FilesystemOptionsFs } from './types.cjs';
import { ValidatePayload, ValidateResult } from '../validator/validate.cjs';
import '../validator/valibot.cjs';
import 'valibot';
import '../validator/types.cjs';
type Filesystem = ReturnType<typeof createFilesystem>;
interface ReadOptions {
recursive?: boolean;
}
interface ReadRecordOptions extends ReadOptions {
reviver?: (key: any, value: any) => any;
default?: Record<string, any>;
schema?: ValidatePayload;
}
type ReadOutput<T extends ReadRecordOptions> = T extends {
schema: ValidatePayload;
} ? ValidateResult<T['schema']> | null : Record<string, any> | null;
declare function createFilesystem<T extends FilesystemOptions | undefined>(options?: T): {
path: FilesystemOptionsPath;
fs: FilesystemOptionsFs;
exists: (path: string) => Promise<boolean>;
existsSync: (path: string) => boolean;
read: {
(filepath: string): Promise<Uint8Array>;
text(filepath: string, options?: any): Promise<any>;
json<T_1 extends ReadRecordOptions>(filepath: string, options?: T_1): Promise<ReadOutput<T_1>>;
yaml(filepath: string, options?: any): Promise<any>;
};
readSync: {
(filepath: string): Uint8Array;
text(filepath: string, defaultValue?: string): string;
json<T_1 extends ReadRecordOptions>(filepath: string, options?: T_1): ReadOutput<T_1>;
yaml(filepath: string, options?: any): any;
};
readdir: (filepath: string) => Promise<string[]>;
readdirSync: (filepath: string) => string[];
write: {
(filename: string, content: Uint8Array, options?: any): Promise<void>;
text(filename: string, content: string, options?: any): Promise<void>;
json(filename: string, content: any, options?: any): Promise<void>;
};
writeSync: {
(filename: string, content: Uint8Array, options?: any): void;
text(filename: string, content: string, options?: any): void;
json(filename: string, content: any, options?: any): void;
};
mkdir: (filepath: string, options?: any) => Promise<void>;
mkdirSync: (filepath: string, options?: any) => void;
remove: (filepath: string) => Promise<void>;
removeSync: (filepath: string) => void;
removeAt: (filepath: string, miliseconds: number) => Promise<boolean>;
};
export { type Filesystem, type ReadOptions, type ReadOutput, type ReadRecordOptions, createFilesystem };