typia
Version:
Superfast runtime validators with only one line
45 lines (44 loc) • 2.14 kB
TypeScript
import fs from "fs";
import path from "path";
export declare namespace FileSystemIdentity {
interface IIdentity {
readonly caseSensitive: boolean;
contains(file: string, directory: string): boolean;
filesystemKey(file: string): string;
isDeclarationFile(file: string): boolean;
isSamePath(x: string, y: string): boolean;
isSupportedExtension(file: string): boolean;
projectFileKey(file: string): string;
}
function create(caseSensitive: boolean, pathApi?: typeof path.posix): IIdentity;
class Policy {
private caseSensitive_;
private location_;
observe(caseSensitive: boolean | undefined, location: string): void;
get(): IIdentity;
}
function inspectDirectory(directory: string): Promise<boolean | undefined>;
function probeDirectory(directory: string): Promise<boolean>;
/**
* Builds the key that decides whether two paths are the same filesystem
* object.
*
* The identity is read from `fs.BigIntStats` rather than `fs.Stats`, because
* `fs.Stats.ino` is a JavaScript number. An NTFS file ID is `(sequenceNumber
* << 48) | mftRecordIndex` and routinely exceeds `Number.MAX_SAFE_INTEGER` —
* in a 4000-directory probe, 1879 of them did — where the spacing between
* representable doubles is 8 or more. Two entries sharing a sequence number
* with MFT record indices within that spacing round to one double. The
* traversal callers would then treat a distinct directory or file as already
* visited and skip it with no diagnostic, and the overwrite guard would
* refuse a legitimate output (samchon/typia#2269).
*
* A filesystem that reports no inode at all keeps the canonical path
* fallback, which is the only identity available there.
*
* @param stat Stats read with `{ bigint: true }`.
* @param realpath Canonical path of the same object.
* @returns Key that is equal for two paths only when they are one object.
*/
function identityKey(stat: Pick<fs.BigIntStats, "dev" | "ino">, realpath: string): string;
}