UNPKG

@synet/patterns

Version:

Robust, battle-tested collection of stable patterns used in Synet packages

54 lines (53 loc) 1.89 kB
import type { IAsyncFileSystem } from '../filesystem/promises'; import { ValueObject } from '../patterns'; import { Result } from '../patterns/result'; import type { IUnit, IUnitOptions } from './unit'; /** * The foundational file interface - everything is a file * This interface can be extended to create specific file types * with additional capabilities as needed. * * */ export interface IFileUnitOptions extends IUnitOptions { name: string; encoding: string; actions: string[]; behaviours: string[]; reletaionships: string[]; } export interface IFileUnit extends IUnit { data: string; format: string; } export declare class FileUnit<U extends IFileUnit = IFileUnit> extends ValueObject<U> { private constructor(); static create<U>(props: U extends IFileUnit ? U : IFileUnit): Result<FileUnit<U extends IFileUnit ? U : IFileUnit>>; static fromJSON<U extends IFileUnit>(json: string): Result<FileUnit<U extends IFileUnit ? U : IFileUnit>>; toJSON(): string; get data(): string; } /** * Interface for file system operations * Generic over file type to allow for different file implementations */ export interface IFileUnitSystem { readFile(path: string): Promise<string>; writeFile(path: string, props: IFileUnit): Promise<void>; deleteFile(path: string): Promise<void>; exists(path: string): Promise<boolean>; } /** * Basic file system implementation * The foundation that everything builds on */ export declare class UnitFileSystem implements IFileUnitSystem { private filesystem; private options?; private name; constructor(filesystem: IAsyncFileSystem, options?: IUnitOptions | undefined); readFile(path: string): Promise<string>; writeFile(path: string, props: IFileUnit): Promise<void>; deleteFile(path: string): Promise<void>; exists(path: string): Promise<boolean>; }