Skip to content

Commit de4fca8

Browse files
Copilothuangyiirene
andcommitted
Replace 'any' types with proper TypeScript types from @objectql/types
- Use ObjectConfig and FieldConfig types in lint command - Create LoadedConfig interface for start command to handle flexible config formats - Maintain type safety while supporting both datasource and datasources config formats Co-authored-by: huangyiirene <7665279+huangyiirene@users.noreply.github.com>
1 parent 4e4606f commit de4fca8

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

packages/tools/cli/src/commands/lint.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ObjectQL } from '@objectql/core';
22
import { ObjectLoader } from '@objectql/platform-node';
3+
import { ObjectConfig, FieldConfig } from '@objectql/types';
34
import * as path from 'path';
45
import chalk from 'chalk';
56

@@ -34,7 +35,7 @@ export async function lint(options: LintOptions) {
3435

3536
// Validate each object
3637
for (const obj of objects) {
37-
const objectConfig = obj as any;
38+
const objectConfig = obj as ObjectConfig;
3839
const name = objectConfig.name;
3940
console.log(chalk.cyan(`Checking object: ${name}`));
4041

@@ -66,7 +67,7 @@ export async function lint(options: LintOptions) {
6667
hasErrors = true;
6768
}
6869

69-
const fieldConfig = field as any;
70+
const fieldConfig = field as FieldConfig;
7071
// Check for required label on fields
7172
if (!fieldConfig.label) {
7273
console.log(chalk.yellow(` ⚠️ Field "${fieldName}" missing label`));

packages/tools/cli/src/commands/start.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ interface StartOptions {
1313
config?: string;
1414
}
1515

16+
// Flexible config type that handles both ObjectQLConfig and custom config formats
17+
interface LoadedConfig {
18+
datasources?: Record<string, any>;
19+
datasource?: Record<string, any>;
20+
[key: string]: any;
21+
}
22+
1623
/**
1724
* Start production server
1825
* Loads configuration from objectql.config.ts/js if available
@@ -24,7 +31,7 @@ export async function start(options: StartOptions) {
2431
console.log(chalk.gray(`Loading schema from: ${rootDir}`));
2532

2633
// Try to load configuration
27-
let config: any = null;
34+
let config: LoadedConfig | null = null;
2835
const configPath = options.config || path.join(process.cwd(), 'objectql.config.ts');
2936

3037
if (fs.existsSync(configPath)) {
@@ -34,17 +41,17 @@ export async function start(options: StartOptions) {
3441
if (configPath.endsWith('.ts')) {
3542
require('ts-node/register');
3643
}
37-
config = require(configPath);
38-
if (config.default) {
39-
config = config.default;
40-
}
44+
const loadedModule = require(configPath);
45+
// Handle both default export and direct export
46+
config = loadedModule.default || loadedModule;
4147
} catch (e: any) {
4248
console.warn(chalk.yellow(`⚠️ Failed to load config: ${e.message}`));
4349
}
4450
}
4551

4652
// Initialize datasource from config or use default SQLite
47-
const datasourceConfig = config?.datasource?.default || {
53+
// Note: Config files may use 'datasource' (singular) while ObjectQLConfig uses 'datasources' (plural)
54+
const datasourceConfig = config?.datasources?.default || config?.datasource?.default || {
4855
client: 'sqlite3',
4956
connection: {
5057
filename: process.env.DATABASE_FILE || './objectql.db'

0 commit comments

Comments
 (0)