@t1mmen/srtd
Version:
Supabase Repeatable Template Definitions (srtd): 🪄 Live-reloading SQL templates for Supabase DX. Make your database changes reviewable and migrations maintainable! 🚀
103 lines (102 loc) • 2.64 kB
TypeScript
/**
* FileSystemService - Handles all file system operations for templates
* Decoupled from business logic, only handles raw file operations
*/
import { EventEmitter } from 'node:events';
import type { Stats } from 'node:fs';
export interface FileSystemConfig {
baseDir: string;
templateDir: string;
filter: string;
migrationDir: string;
watchOptions?: {
ignoreInitial?: boolean;
stabilityThreshold?: number;
pollInterval?: number;
};
}
export interface TemplateFile {
path: string;
name: string;
content: string;
hash: string;
relativePath: string;
}
export interface WatchEvent {
type: 'added' | 'changed' | 'removed';
path: string;
relativePath: string;
name: string;
}
export declare class FileSystemService extends EventEmitter {
private config;
private watcher;
private debouncedHandlers;
constructor(config: FileSystemConfig);
/**
* Find all template files matching the configured pattern
*/
findTemplates(): Promise<string[]>;
/**
* Read a template file and return its content with metadata
*/
readTemplate(templatePath: string): Promise<TemplateFile>;
/**
* Check if a file exists
*/
fileExists(filePath: string): Promise<boolean>;
/**
* Write content to a file
*/
writeFile(filePath: string, content: string): Promise<void>;
/**
* Delete a file
*/
deleteFile(filePath: string): Promise<void>;
/**
* Rename a file
*/
renameFile(oldPath: string, newPath: string): Promise<void>;
/**
* Get file stats
*/
getFileStats(filePath: string): Promise<Stats>;
/**
* Calculate MD5 hash of content
* Normalizes line endings to LF for cross-platform consistency
* (Fix contributed by @louisandred - https://github.com/t1mmen/srtd/pull/42)
*/
private calculateHash;
/**
* Watch templates for changes
*/
watchTemplates(): Promise<void>;
/**
* Stop watching templates
*/
stopWatching(): Promise<void>;
/**
* Emit watch event with debouncing
*/
private debouncedEmit;
/**
* Emit a watch event
*/
private emitWatchEvent;
/**
* Clean up resources
*/
dispose(): Promise<void>;
/**
* Get migration file path for a template
*/
getMigrationPath(templateName: string, timestamp: string): string;
/**
* List all migration files
*/
listMigrations(): Promise<string[]>;
/**
* Read a migration file
*/
readMigration(migrationPath: string): Promise<string>;
}