/** * Filesystem path helpers for project management. * * Projects in `spectral serve` are user-owned directories on disk. We accept * paths typed by the user from the browser, so two small concerns: * * - Tilde expansion: `~/foo/bar` is the natural way to refer to a path * inside `$HOME`. Node's `path` module does not expand tildes; we do it * ourselves with a leading-segment check (NOT a global string replace — * `~user/...` and embedded `~` are intentionally left alone). * - Validation: the path must exist, must be a directory, and must be * readable. We do NOT attempt to verify writability — spectral may want to * create files inside it, but failure modes there surface naturally * through spectral's tools, and a write probe here would create stray files. * - Create-if-missing: `validateProjectPath(path, {createIfMissing:true})` * creates the directory (recursively) before validating. Used by POST * /api/projects so users can point at a brand-new folder; mkdir failures * surface as `Cannot create directory:` errors, while everything else * falls through the normal existence/type checks below. * * Both helpers are synchronous because they're called on hot HTTP paths * (POST /api/projects) where blocking is acceptable: the operation is rare * and the user is waiting on the response anyway. `node:fs` sync calls in * this regime are simpler than juggling promises through validation. */ /** * Expand a leading `~` or `~/` to the user's home directory and return an * absolute, normalized path. * * Behavior: * - `~` → `$HOME` * - `~/foo` → `$HOME/foo` * - `/abs/path` → `/abs/path` (unchanged, normalized) * - `relative` → resolved against `$HOME` (NOT process.cwd, since the * server runs from `$HOME` and "relative to home" matches the user's * mental model when typing into a form) * - `~user/...` → returned as-is and resolved against `$HOME`. We do NOT * attempt to look up other users' home directories — out of scope. */ export declare function expandPath(input: string): string; export interface ProjectPathValidation { ok: boolean; /** Absolute, normalized path (set when ok=true and also for some errors). */ path: string; /** Human-friendly error message (set when ok=false). */ error?: string; } /** * Validate a user-supplied project path. * * Returns `{ok:true, path}` for a real, accessible directory. On failure, * `error` carries a message suitable for surfacing to the user. The expanded * path is included in both cases so callers can echo it back in errors. * * With `options.createIfMissing`, a missing path is created recursively first * (project creation should not require a prior manual `mkdir`), then validated * like any other path. */ export declare function validateProjectPath(input: string, options?: { createIfMissing?: boolean; }): ProjectPathValidation; //# sourceMappingURL=paths.d.ts.map