Skip to content

Commit 03ca2bb

Browse files
committed
chore: prettier the entire codebase
1 parent 1f86075 commit 03ca2bb

31 files changed

+956
-815
lines changed

.prettierrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"tabWidth": 2,
44
"useTabs": false,
55
"semi": true,
6-
"singleQuote": true,
6+
"singleQuote": false,
77
"trailingComma": "es5",
88
"bracketSpacing": true,
99
"arrowParens": "always"

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
"better-sqlite3": "^11.9.0",
2828
"dotenv": "^16.4.7",
2929
"express": "^4.18.2",
30-
"mssql": "^11.0.1",
3130
"mariadb": "^3.4.0",
31+
"mssql": "^11.0.1",
3232
"mysql2": "^3.13.0",
3333
"pg": "^8.13.3",
3434
"zod": "^3.24.2"
@@ -40,6 +40,7 @@
4040
"@types/node": "^22.13.10",
4141
"@types/pg": "^8.11.11",
4242
"cross-env": "^7.0.3",
43+
"prettier": "^3.5.3",
4344
"ts-node": "^10.9.2",
4445
"tsup": "^8.4.0",
4546
"tsx": "^4.19.3",

pnpm-lock.yaml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/config/demo-loader.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/**
22
* Demo data loader for SQLite in-memory database
3-
*
3+
*
44
* This module loads the sample employee database into the SQLite in-memory database
55
* when the --demo flag is specified.
66
*/
7-
import fs from 'fs';
8-
import path from 'path';
9-
import { fileURLToPath } from 'url';
7+
import fs from "fs";
8+
import path from "path";
9+
import { fileURLToPath } from "url";
1010

1111
// Create __dirname equivalent for ES modules
1212
const __filename = fileURLToPath(import.meta.url);
@@ -15,21 +15,21 @@ const __dirname = path.dirname(__filename);
1515
// Path to sample data files - will be bundled with the package
1616
// Try different paths to find the SQL files in development or production
1717
let DEMO_DATA_DIR: string;
18-
const projectRootPath = path.join(__dirname, '..', '..', '..');
19-
const projectResourcesPath = path.join(projectRootPath, 'resources', 'employee-sqlite');
20-
const distPath = path.join(__dirname, 'resources', 'employee-sqlite');
18+
const projectRootPath = path.join(__dirname, "..", "..", "..");
19+
const projectResourcesPath = path.join(projectRootPath, "resources", "employee-sqlite");
20+
const distPath = path.join(__dirname, "resources", "employee-sqlite");
2121

2222
// First try the project root resources directory (for development)
2323
if (fs.existsSync(projectResourcesPath)) {
2424
DEMO_DATA_DIR = projectResourcesPath;
25-
}
25+
}
2626
// Then try dist directory (for production)
2727
else if (fs.existsSync(distPath)) {
2828
DEMO_DATA_DIR = distPath;
2929
}
3030
// Fallback to a relative path from the current directory
3131
else {
32-
DEMO_DATA_DIR = path.join(process.cwd(), 'resources', 'employee-sqlite');
32+
DEMO_DATA_DIR = path.join(process.cwd(), "resources", "employee-sqlite");
3333
if (!fs.existsSync(DEMO_DATA_DIR)) {
3434
throw new Error(`Could not find employee-sqlite resources in any of the expected locations:
3535
- ${projectResourcesPath}
@@ -43,35 +43,35 @@ else {
4343
*/
4444
export function loadSqlFile(fileName: string): string {
4545
const filePath = path.join(DEMO_DATA_DIR, fileName);
46-
return fs.readFileSync(filePath, 'utf8');
46+
return fs.readFileSync(filePath, "utf8");
4747
}
4848

4949
/**
5050
* Get SQLite DSN for in-memory database
5151
*/
5252
export function getInMemorySqliteDSN(): string {
53-
return 'sqlite::memory:';
53+
return "sqlite::memory:";
5454
}
5555

5656
/**
5757
* Load SQL files sequentially
5858
*/
5959
export function getSqliteInMemorySetupSql(): string {
6060
// First, load the schema
61-
let sql = loadSqlFile('employee.sql');
62-
61+
let sql = loadSqlFile("employee.sql");
62+
6363
// Replace .read directives with the actual file contents
6464
// This is necessary because in-memory SQLite can't use .read
6565
const readRegex = /\.read\s+([a-zA-Z0-9_]+\.sql)/g;
6666
let match;
67-
67+
6868
while ((match = readRegex.exec(sql)) !== null) {
6969
const includePath = match[1];
7070
const includeContent = loadSqlFile(includePath);
71-
71+
7272
// Replace the .read line with the file contents
7373
sql = sql.replace(match[0], includeContent);
7474
}
75-
75+
7676
return sql;
7777
}

src/config/env.ts

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import dotenv from "dotenv";
2-
import path from 'path';
3-
import fs from 'fs';
4-
import { fileURLToPath } from 'url';
2+
import path from "path";
3+
import fs from "fs";
4+
import { fileURLToPath } from "url";
55

66
// Create __dirname equivalent for ES modules
77
const __filename = fileURLToPath(import.meta.url);
@@ -12,25 +12,25 @@ export function parseCommandLineArgs() {
1212
// Check if any args start with '--' (the way tsx passes them)
1313
const args = process.argv.slice(2);
1414
const parsedManually: Record<string, string> = {};
15-
15+
1616
for (let i = 0; i < args.length; i++) {
1717
const arg = args[i];
18-
if (arg.startsWith('--')) {
19-
const [key, value] = arg.substring(2).split('=');
18+
if (arg.startsWith("--")) {
19+
const [key, value] = arg.substring(2).split("=");
2020
if (value) {
2121
// Handle --key=value format
2222
parsedManually[key] = value;
23-
} else if (i + 1 < args.length && !args[i + 1].startsWith('--')) {
23+
} else if (i + 1 < args.length && !args[i + 1].startsWith("--")) {
2424
// Handle --key value format
2525
parsedManually[key] = args[i + 1];
2626
i++; // Skip the next argument as it's the value
2727
} else {
2828
// Handle --key format (boolean flag)
29-
parsedManually[key] = 'true';
29+
parsedManually[key] = "true";
3030
}
3131
}
3232
}
33-
33+
3434
// Just use the manually parsed args - removed parseArgs dependency for Node.js <18.3.0 compatibility
3535
return parsedManually;
3636
}
@@ -41,19 +41,19 @@ export function parseCommandLineArgs() {
4141
*/
4242
export function loadEnvFiles(): string | null {
4343
// Determine if we're in development or production mode
44-
const isDevelopment = process.env.NODE_ENV === 'development' || process.argv[1]?.includes('tsx');
44+
const isDevelopment = process.env.NODE_ENV === "development" || process.argv[1]?.includes("tsx");
4545

4646
// Select environment file names based on environment
47-
const envFileNames = isDevelopment
48-
? ['.env.local', '.env'] // In development, try .env.local first, then .env
49-
: ['.env']; // In production, only look for .env
47+
const envFileNames = isDevelopment
48+
? [".env.local", ".env"] // In development, try .env.local first, then .env
49+
: [".env"]; // In production, only look for .env
5050

5151
// Build paths to check for environment files
5252
const envPaths = [];
5353
for (const fileName of envFileNames) {
5454
envPaths.push(
5555
fileName, // Current working directory
56-
path.join(__dirname, '..', '..', fileName), // Two levels up (src/config -> src -> root)
56+
path.join(__dirname, "..", "..", fileName), // Two levels up (src/config -> src -> root)
5757
path.join(process.cwd(), fileName) // Explicit current working directory
5858
);
5959
}
@@ -67,7 +67,7 @@ export function loadEnvFiles(): string | null {
6767
return path.basename(envPath);
6868
}
6969
}
70-
70+
7171
return null;
7272
}
7373

@@ -77,7 +77,7 @@ export function loadEnvFiles(): string | null {
7777
*/
7878
export function isDemoMode(): boolean {
7979
const args = parseCommandLineArgs();
80-
return args.demo === 'true';
80+
return args.demo === "true";
8181
}
8282

8383
/**
@@ -87,85 +87,85 @@ export function isDemoMode(): boolean {
8787
export function resolveDSN(): { dsn: string; source: string; isDemo?: boolean } | null {
8888
// Get command line arguments
8989
const args = parseCommandLineArgs();
90-
90+
9191
// Check for demo mode first (highest priority)
9292
if (isDemoMode()) {
9393
// Will use in-memory SQLite with demo data
94-
return {
95-
dsn: 'sqlite::memory:',
96-
source: 'demo mode',
97-
isDemo: true
94+
return {
95+
dsn: "sqlite::memory:",
96+
source: "demo mode",
97+
isDemo: true,
9898
};
9999
}
100-
101-
// 1. Check command line arguments
100+
101+
// 1. Check command line arguments
102102
if (args.dsn) {
103-
return { dsn: args.dsn, source: 'command line argument' };
103+
return { dsn: args.dsn, source: "command line argument" };
104104
}
105-
105+
106106
// 2. Check environment variables before loading .env
107107
if (process.env.DSN) {
108-
return { dsn: process.env.DSN, source: 'environment variable' };
108+
return { dsn: process.env.DSN, source: "environment variable" };
109109
}
110-
110+
111111
// 3. Try loading from .env files
112112
const loadedEnvFile = loadEnvFiles();
113113
if (loadedEnvFile && process.env.DSN) {
114114
return { dsn: process.env.DSN, source: `${loadedEnvFile} file` };
115115
}
116-
116+
117117
return null;
118118
}
119119

120120
/**
121121
* Resolve transport type from command line args or environment variables
122122
* Returns 'stdio' or 'sse', with 'stdio' as the default
123123
*/
124-
export function resolveTransport(): { type: 'stdio' | 'sse'; source: string } {
124+
export function resolveTransport(): { type: "stdio" | "sse"; source: string } {
125125
// Get command line arguments
126126
const args = parseCommandLineArgs();
127-
127+
128128
// 1. Check command line arguments first (highest priority)
129129
if (args.transport) {
130-
const type = args.transport === 'sse' ? 'sse' : 'stdio';
131-
return { type, source: 'command line argument' };
130+
const type = args.transport === "sse" ? "sse" : "stdio";
131+
return { type, source: "command line argument" };
132132
}
133-
133+
134134
// 2. Check environment variables
135135
if (process.env.TRANSPORT) {
136-
const type = process.env.TRANSPORT === 'sse' ? 'sse' : 'stdio';
137-
return { type, source: 'environment variable' };
136+
const type = process.env.TRANSPORT === "sse" ? "sse" : "stdio";
137+
return { type, source: "environment variable" };
138138
}
139-
139+
140140
// 3. Default to stdio
141-
return { type: 'stdio', source: 'default' };
141+
return { type: "stdio", source: "default" };
142142
}
143143

144144
/**
145145
* Resolve port from command line args or environment variables
146146
* Returns port number with 8080 as the default
147-
*
147+
*
148148
* Note: The port option is only applicable when using --transport=sse
149149
* as it controls the HTTP server port for SSE connections.
150150
*/
151151
export function resolvePort(): { port: number; source: string } {
152152
// Get command line arguments
153153
const args = parseCommandLineArgs();
154-
154+
155155
// 1. Check command line arguments first (highest priority)
156156
if (args.port) {
157157
const port = parseInt(args.port, 10);
158-
return { port, source: 'command line argument' };
158+
return { port, source: "command line argument" };
159159
}
160-
160+
161161
// 2. Check environment variables
162162
if (process.env.PORT) {
163163
const port = parseInt(process.env.PORT, 10);
164-
return { port, source: 'environment variable' };
164+
return { port, source: "environment variable" };
165165
}
166-
166+
167167
// 3. Default to 8080
168-
return { port: 8080, source: 'default' };
168+
return { port: 8080, source: "default" };
169169
}
170170

171171
/**
@@ -178,16 +178,16 @@ export function redactDSN(dsn: string): string {
178178
try {
179179
// Create a URL object to parse the DSN
180180
const url = new URL(dsn);
181-
181+
182182
// Replace the password with asterisks
183183
if (url.password) {
184-
url.password = '*******';
184+
url.password = "*******";
185185
}
186-
186+
187187
// Return the sanitized DSN
188188
return url.toString();
189189
} catch (error) {
190190
// If parsing fails, do basic redaction with regex
191-
return dsn.replace(/\/\/([^:]+):([^@]+)@/, '//$1:***@');
191+
return dsn.replace(/\/\/([^:]+):([^@]+)@/, "//$1:***@");
192192
}
193193
}

0 commit comments

Comments
 (0)