| 1 | import { IndexTag } from ".."; |
| 2 | |
| 3 | // Maximum length for table names to stay under OS filename limits |
| 4 | const MAX_TABLE_NAME_LENGTH = 240; |
| 5 | |
| 6 | // Leave room for branch and artifactId |
| 7 | const MAX_DIR_LENGTH = 200; |
| 8 | |
| 9 | /** |
| 10 | * Converts an IndexTag to a string representation, safely handling long paths. |
| 11 | * |
| 12 | * The string is used as a table name and identifier in various places, so it needs |
| 13 | * to stay under OS filename length limits (typically 255 chars). This is especially |
| 14 | * important for dev containers where the directory path can be very long due to |
| 15 | * containing container configuration. |
| 16 | * |
| 17 | * The format is: "{directory}::{branch}::{artifactId}" |
| 18 | * |
| 19 | * To handle long paths: |
| 20 | * 1. First tries the full string - most backwards compatible |
| 21 | * 2. If too long, truncates directory from the beginning to maintain uniqueness |
| 22 | * (since final parts of paths are more unique than prefixes) |
| 23 | * 3. Finally ensures entire string stays under MAX_TABLE_NAME_LENGTH for OS compatibility |
| 24 | * |
| 25 | * @param tag The tag containing directory, branch, and artifactId |
| 26 | * @returns A string representation safe for use as a table name |
| 27 | */ |
| 28 | export function tagToString(tag: IndexTag): string { |
| 29 | const result = `${tag.directory}::${tag.branch}::${tag.artifactId}`; |
| 30 | |
| 31 | if (result.length <= MAX_TABLE_NAME_LENGTH) { |
| 32 | return result; |
| 33 | } |
| 34 | |
| 35 | // Truncate from the beginning of directory path to preserve the more unique end parts |
| 36 | const dir = |
| 37 | tag.directory.length > MAX_DIR_LENGTH |
| 38 | ? tag.directory.slice(tag.directory.length - MAX_DIR_LENGTH) |
| 39 | : tag.directory; |
| 40 | |
| 41 | return `${dir}::${tag.branch}::${tag.artifactId}`.slice( |
| 42 | 0, |
| 43 | MAX_TABLE_NAME_LENGTH, |
| 44 | ); |
| 45 | } |