@mdfriday/foundry
Version:
The core engine of MDFriday. Convert Markdown and shortcodes into fully themed static sites – Hugo-style, powered by TypeScript.
219 lines • 6.25 kB
TypeScript
export interface FileInfo {
name(): string;
size(): number;
mode(): number;
modTime(): Date;
isDir(): boolean;
sys(): any;
}
export interface File {
close(): Promise<void>;
read(buffer: Uint8Array): Promise<{
bytesRead: number;
buffer: Uint8Array;
}>;
readAt(buffer: Uint8Array, offset: number): Promise<{
bytesRead: number;
buffer: Uint8Array;
}>;
seek(offset: number, whence: number): Promise<number>;
write(buffer: Uint8Array): Promise<{
bytesWritten: number;
buffer: Uint8Array;
}>;
writeAt(buffer: Uint8Array, offset: number): Promise<{
bytesWritten: number;
buffer: Uint8Array;
}>;
name(): string;
readdir(count: number): Promise<FileInfo[]>;
readdirnames(n: number): Promise<string[]>;
stat(): Promise<FileInfo>;
sync(): Promise<void>;
truncate(size: number): Promise<void>;
writeString(s: string): Promise<{
bytesWritten: number;
}>;
}
export interface Fs {
/**
* Create creates a file in the filesystem, returning the file and an
* error, if any happens.
*/
create(name: string): Promise<File>;
/**
* Mkdir creates a directory in the filesystem, return an error if any
* happens.
*/
mkdir(name: string, perm: number): Promise<void>;
/**
* MkdirAll creates a directory path and all parents that does not exist
* yet.
*/
mkdirAll(path: string, perm: number): Promise<void>;
/**
* Open opens a file, returning it or an error, if any happens.
*/
open(name: string): Promise<File>;
/**
* OpenFile opens a file using the given flags and the given mode.
*/
openFile(name: string, flag: number, perm: number): Promise<File>;
/**
* Remove removes a file identified by name, returning an error, if any
* happens.
*/
remove(name: string): Promise<void>;
/**
* RemoveAll removes a directory path and any children it contains. It
* does not fail if the path does not exist (return null).
*/
removeAll(path: string): Promise<void>;
/**
* Rename renames a file.
*/
rename(oldname: string, newname: string): Promise<void>;
/**
* Stat returns a FileInfo describing the named file, or an error, if any
* happens.
*/
stat(name: string): Promise<FileInfo>;
/**
* The name of this FileSystem
*/
name(): string;
/**
* Chmod changes the mode of the named file to mode.
*/
chmod(name: string, mode: number): Promise<void>;
/**
* Chown changes the uid and gid of the named file.
*/
chown(name: string, uid: number, gid: number): Promise<void>;
/**
* Chtimes changes the access and modification times of the named file
*/
chtimes(name: string, atime: Date, mtime: Date): Promise<void>;
}
/**
* File system error constants
* Equivalent to Go's afero error variables
*/
export declare class FsError extends Error {
code?: string | undefined;
constructor(message: string, code?: string | undefined);
}
export declare const ErrFileClosed: FsError;
export declare const ErrOutOfRange: FsError;
export declare const ErrTooLarge: FsError;
export declare const ErrFileNotFound: FsError;
export declare const ErrFileExists: FsError;
export declare const ErrDestinationExists: FsError;
/**
* File open flags (equivalent to Go's vo package flags)
*/
export declare enum OpenFlags {
O_RDONLY = 0,
O_WRONLY = 1,
O_RDWR = 2,
O_APPEND = 8,
O_CREATE = 64,
O_EXCL = 128,
O_SYNC = 256,
O_TRUNC = 512
}
export interface FileMetaInfo extends FileInfo {
fileName(): string;
relativeFilename(): string;
component(): string;
root(): string;
open(): Promise<File>;
}
/**
* Walk function type - called for each file/directory during walk
*/
export type WalkFunc = (path: string, info: FileMetaInfo) => Promise<void | Error>;
/**
* Walk hook function type - called before/after processing directory contents
*/
export type WalkHook = (dir: FileMetaInfo, path: string, readdir: FileMetaInfo[]) => Promise<FileMetaInfo[]>;
/**
* WalkCallback structure containing hooks and walk function
*/
export interface WalkCallback {
hookPre?: WalkHook;
walkFn: WalkFunc;
hookPost?: WalkHook;
}
/**
* WalkwayConfig structure containing hooks and walk function
*/
export interface WalkwayConfig {
info?: FileMetaInfo;
dirEntries?: FileMetaInfo[];
ignoreFile?: (filename: string) => boolean;
failOnNotExist?: boolean;
sortDirEntries?: boolean;
}
/**
* Walk-related errors
*/
export declare const ErrSkipDir: Error;
export declare const ErrWalkAlreadyWalked: FsError;
/**
* Filesystem iterator interface for iterating over wrapped filesystems
* TypeScript version of Go's FilesystemIterator
*/
export interface FilesystemIterator {
filesystem(i: number): Fs | null;
numFilesystems(): number;
}
/**
* Directory merger function type
* TypeScript version of Go's DirsMerger
*/
export type DirsMerger = (lofi: FileInfo[], bofi: FileInfo[]) => FileInfo[];
/**
* OverlayFs options configuration
* TypeScript version of Go's Options
*/
export interface OverlayFsOptions {
fss: Fs[];
firstWritable?: boolean;
dirsMerger?: DirsMerger;
}
/**
* OverlayFs interface extending base Fs functionality
* TypeScript version of Go's OverlayFs interface
*/
export interface OverlayFs extends Fs, FilesystemIterator {
append(...fss: Fs[]): OverlayFs;
withDirsMerger(merger: DirsMerger): OverlayFs;
}
/**
* Directory opener function type
*/
export type DirOpener = () => Promise<File>;
/**
* Info function type for directory stats
*/
export type InfoFunc = () => Promise<FileInfo>;
/**
* Overlay directory options
*/
export interface OverlayDirOptions {
name?: string;
fss?: Fs[];
dirOpeners?: DirOpener[];
info?: InfoFunc;
merge?: DirsMerger;
}
/**
* OverlayFs errors
*/
export declare class OverlayFsError extends FsError {
constructor(message: string, code?: string);
}
export declare const ErrNoFilesystems: OverlayFsError;
export declare const ErrOperationNotSupported: OverlayFsError;
//# sourceMappingURL=type.d.ts.map