import type { Tagged } from "type-fest"; /** Represents a file's basename (filename without directory path, but including extension) */ export type FileBaseName = Tagged; export type AbsolutePath = Tagged; export declare function toAbsolutePath(thePath: string): AbsolutePath; export type ValidEnvName = Tagged; export type ValidScriptFormat = Tagged; export type ValidScriptName = Tagged; export type ValidScriptTimestamp = Tagged; export type ParsedScriptName = ValidEnvName, LegalScriptFormats extends ValidScriptFormat = ValidScriptFormat> = { date: Date; type: "migration"; format: LegalScriptFormats; env?: undefined; name: string; } | { date: Date; type: "seed"; format: LegalScriptFormats; env: LegalEnvNames; name: string; } | { date: Date; type: "snapshot-schema"; format: LegalScriptFormats; env?: undefined; name?: undefined; } | { date: Date; type: "snapshot-seed"; format: LegalScriptFormats; env: LegalEnvNames; name?: undefined; }; /** * Formats a Date as a timestamp string in the format used for migration * prefixes. Validates it in the process (date's time cannot be NaN). * * Format: YYYY.MM.DDTHH.MM.SS (e.g., "2024.02.04T19.00.00") */ export declare function toValidScriptTimestamp(date: Date): ValidScriptTimestamp; /** * Validates that a string is a valid script name (user-provided portion). * Throws if invalid. * * Names: * - Cannot be empty or whitespace-only * - Cannot contain dots (used as delimiters in filenames) * - Cannot be "snapshot-schema" or "snapshot-seed" (reserved) * - Must match pattern: alphanumeric, hyphens, underscores */ export declare function toValidScriptName(name: string): ValidScriptName; /** * Parses a script filename to extract its components. This is the inverse of * {@link nameScript}. Throws if the filename doesn't match any known script * pattern. * * Accepts a FileBaseName to ensure callers have explicitly extracted the * basename. Use {@link toFileBaseName} to convert a path to a FileBaseName. * * @example * parseScriptName(toFileBaseName("2024.02.04T19.00.00.add-users.sql")) * // => { timestamp: "2024.02.04T19.00.00", type: "migration", format: "sql", env: undefined, name: "add-users" } * * parseScriptName(toFileBaseName("2024.02.04T19.00.00.add-users.seed.local-dev.sql")) * // => { timestamp: "2024.02.04T19.00.00", type: "seed", format: "sql", env: "local-dev", name: "add-users" } * * parseScriptName(toFileBaseName("2024.02.04T19.00.00.snapshot-schema.sql")) * // => { timestamp: "2024.02.04T19.00.00", type: "snapshot-schema", format: "sql", env: undefined, name: undefined } * * parseScriptName(toFileBaseName("2024.02.04T19.00.00.snapshot-seed.local-dev.sql")) * // => { timestamp: "2024.02.04T19.00.00", type: "snapshot-seed", format: "sql", env: "local-dev", name: undefined } */ export declare function parseScriptName, LegalEnvName extends ValidEnvName>(scriptName: FileBaseName, legalScriptFormats: readonly LegalScriptFormat[], legalEnvNames: readonly LegalEnvName[]): ParsedScriptName; export declare function parseTimestamp(timestamp: ValidScriptTimestamp): Date; /** * Generates the full filename for a script file. * This function enforces a naming convention that allows us to identify the * script type and, for seeds, which environment it should run in. * * Returns a FileBaseName since the generated name is always a valid basename. * * Throws if any component is invalid (contains forbidden characters, etc.) */ export declare function nameScript(opts: ParsedScriptName): ValidScriptName; //# sourceMappingURL=script-name-parsing.d.ts.map