Skip to content

Commit bddae97

Browse files
Copilothuangyiirene
andcommitted
Fix type safety: use ObjectConfig and IObjectQL instead of any
Co-authored-by: huangyiirene <7665279+huangyiirene@users.noreply.github.com>
1 parent 935da53 commit bddae97

1 file changed

Lines changed: 16 additions & 13 deletions

File tree

  • packages/tools/cli/src/commands

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

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import * as fs from 'fs';
22
import * as path from 'path';
33
import chalk from 'chalk';
44
import * as yaml from 'js-yaml';
5-
import { IntrospectedSchema, IntrospectedTable, IntrospectedColumn } from '@objectql/types';
5+
import { IntrospectedSchema, IntrospectedTable, IntrospectedColumn, ObjectConfig, IObjectQL } from '@objectql/types';
66

77
interface SyncOptions {
88
config?: string;
99
output?: string;
1010
tables?: string[];
1111
force?: boolean;
12-
app?: any; // Allow passing app instance directly for testing
12+
app?: IObjectQL; // Allow passing app instance directly for testing
1313
}
1414

1515
/**
@@ -22,7 +22,7 @@ export async function syncDatabase(options: SyncOptions) {
2222
console.log(chalk.blue('🔄 Syncing database schema to ObjectQL...'));
2323
console.log(chalk.gray(`Output directory: ${outputDir}\n`));
2424

25-
let app: any = options.app;
25+
let app: IObjectQL | undefined = options.app;
2626
const shouldClose = !options.app; // Only close if we loaded it ourselves
2727

2828
try {
@@ -32,7 +32,7 @@ export async function syncDatabase(options: SyncOptions) {
3232
}
3333

3434
// Check if driver supports introspection
35-
const driver = app.datasources?.default;
35+
const driver = app.datasource('default');
3636
if (!driver || !driver.introspectSchema) {
3737
const errorMsg = 'The configured driver does not support schema introspection. Only SQL drivers (PostgreSQL, MySQL, SQLite) support this feature.';
3838
console.error(chalk.red(`❌ ${errorMsg}`));
@@ -117,12 +117,15 @@ export async function syncDatabase(options: SyncOptions) {
117117
throw error;
118118
} finally {
119119
// Ensure connection is closed if we opened it
120-
if (shouldClose) {
121-
if (app && app.close) {
122-
await app.close();
123-
} else if (app && app.datasources && app.datasources.default && (app.datasources.default as any).disconnect) {
124-
// Fallback for older versions if close isn't available
125-
await (app.datasources.default as any).disconnect();
120+
if (shouldClose && app) {
121+
if (app.close) {
122+
await app.close();
123+
} else {
124+
// Fallback for older versions if close isn't available
125+
const driver = app.datasource('default');
126+
if (driver && (driver as any).disconnect) {
127+
await (driver as any).disconnect();
128+
}
126129
}
127130
}
128131
}
@@ -131,8 +134,8 @@ export async function syncDatabase(options: SyncOptions) {
131134
/**
132135
* Generate ObjectQL object definition from introspected table
133136
*/
134-
function generateObjectDefinition(table: IntrospectedTable, schema: IntrospectedSchema): any {
135-
const obj: any = {
137+
function generateObjectDefinition(table: IntrospectedTable, schema: IntrospectedSchema): ObjectConfig {
138+
const obj: ObjectConfig = {
136139
name: table.name,
137140
label: formatLabel(table.name),
138141
fields: {}
@@ -266,7 +269,7 @@ function formatLabel(name: string): string {
266269
/**
267270
* Load ObjectQL instance from config file
268271
*/
269-
async function loadObjectQLInstance(configPath?: string): Promise<any> {
272+
async function loadObjectQLInstance(configPath?: string): Promise<IObjectQL> {
270273
const cwd = process.cwd();
271274

272275
// Try to load from config file

0 commit comments

Comments
 (0)