blob: f365f837ca1e1746cc23e67ebdbe3413cd7a7976 [file] [log] [blame]
gioc31bf142025-06-16 07:48:20 +00001import { ConfigVar, ConfigVarSemanticType } from "./analyze.js";
gioa71316d2025-05-24 09:41:36 +04002
3export function augmentConfigVar(cv: ConfigVar) {
4 if (cv.semanticType != null) {
5 return;
6 }
7 const name = cv.name.toLowerCase();
8 const value = cv.defaultValue ? String(cv.defaultValue).toLowerCase() : "";
9 if (name.includes("postgres") || name.includes("pg")) {
10 if (name.includes("url")) cv.semanticType = ConfigVarSemanticType.POSTGRES_URL;
11 if (name.includes("password") || name.includes("pass"))
12 cv.semanticType = ConfigVarSemanticType.POSTGRES_PASSWORD;
13 if (name.includes("user")) cv.semanticType = ConfigVarSemanticType.POSTGRES_USER;
14 if (
15 name.includes("db_name") ||
16 name.includes("database_name") ||
17 (name.includes("db") && !name.includes("url"))
18 )
19 cv.semanticType = ConfigVarSemanticType.POSTGRES_DB;
20 if (name.includes("port")) cv.semanticType = ConfigVarSemanticType.POSTGRES_PORT;
21 if (name.includes("host")) cv.semanticType = ConfigVarSemanticType.POSTGRES_HOST;
22 if (name.includes("sslmode") || name.includes("ssl")) cv.semanticType = ConfigVarSemanticType.POSTGRES_SSL;
23 }
24 if (name.includes("mongo")) {
25 if (name.includes("url") || name.includes("uri")) cv.semanticType = ConfigVarSemanticType.MONGO_URL;
26 if (name.includes("password") || name.includes("pass")) cv.semanticType = ConfigVarSemanticType.MONGO_PASSWORD;
27 if (name.includes("user")) cv.semanticType = ConfigVarSemanticType.MONGO_USER;
28 if (
29 name.includes("db_name") ||
30 name.includes("database_name") ||
31 (name.includes("db") && !name.includes("url"))
32 )
33 cv.semanticType = ConfigVarSemanticType.MONGO_DB;
34 if (name.includes("port")) cv.semanticType = ConfigVarSemanticType.MONGO_PORT;
35 if (name.includes("host")) cv.semanticType = ConfigVarSemanticType.MONGO_HOST;
36 if (name.includes("ssl")) cv.semanticType = ConfigVarSemanticType.MONGO_SSL;
37 }
38 if (name.includes("sqlite_path") || value.endsWith(".sqlite") || value.endsWith(".db3") || value.endsWith(".db")) {
39 cv.semanticType = ConfigVarSemanticType.SQLITE_PATH;
40 }
41 if (name.includes("sqlite") && (name.includes("url") || name.includes("uri") || name.includes("path"))) {
42 cv.semanticType = ConfigVarSemanticType.SQLITE_PATH;
43 }
44 if (name.includes("database_url") || name.includes("db_url")) {
45 cv.semanticType = ConfigVarSemanticType.DATABASE_URL;
46 }
47 if (name.includes("path") || name.includes("file_path") || name.includes("dir") || name.includes("directory")) {
48 if (
49 !name.includes("url") &&
50 (value.startsWith("./") || value.startsWith("../") || value.startsWith("/") || /^[a-z]:[\\/]/.test(value))
51 ) {
52 cv.semanticType = ConfigVarSemanticType.FILESYSTEM_PATH;
53 }
54 }
55 if (
56 !name.includes("url") &&
57 (value.startsWith("./") || value.startsWith("../") || value.startsWith("/") || /^[a-z]:[\\/]/.test(value))
58 ) {
59 cv.semanticType = ConfigVarSemanticType.FILESYSTEM_PATH;
60 }
61 if (name.includes("port")) {
62 cv.semanticType = ConfigVarSemanticType.PORT;
63 }
64}