Fix remaining TypeScript 'Untyped function calls' errors
- Add DatabaseAdapter type imports where needed - Properly type database adapter calls with type assertions - Fix type mismatches in schemaMappingService - Fix ensureInitialized calls on DatabaseAdapter
This commit is contained in:
@@ -249,7 +249,7 @@ app.listen(PORT, async () => {
|
|||||||
if (db) {
|
if (db) {
|
||||||
await db.ensureInitialized?.();
|
await db.ensureInitialized?.();
|
||||||
try {
|
try {
|
||||||
const schemaRow = await (db as any).queryOne<{ count: number }>(
|
const schemaRow = await (db.queryOne as <T>(sql: string, params?: any[]) => Promise<T | null>)<{ count: number }>(
|
||||||
`SELECT COUNT(*) as count FROM schemas`
|
`SELECT COUNT(*) as count FROM schemas`
|
||||||
);
|
);
|
||||||
hasSchemas = (schemaRow?.count || 0) > 0;
|
hasSchemas = (schemaRow?.count || 0) > 0;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { logger } from './logger.js';
|
|||||||
import { normalizedCacheStore as cacheStore } from './normalizedCacheStore.js';
|
import { normalizedCacheStore as cacheStore } from './normalizedCacheStore.js';
|
||||||
import { jiraAssetsClient, JiraObjectNotFoundError } from './jiraAssetsClient.js';
|
import { jiraAssetsClient, JiraObjectNotFoundError } from './jiraAssetsClient.js';
|
||||||
import type { CMDBObject } from '../generated/jira-types.js';
|
import type { CMDBObject } from '../generated/jira-types.js';
|
||||||
|
import type { DatabaseAdapter } from './database/interface.js';
|
||||||
|
|
||||||
export interface BrokenReference {
|
export interface BrokenReference {
|
||||||
object_id: string;
|
object_id: string;
|
||||||
@@ -150,7 +151,8 @@ class DataIntegrityService {
|
|||||||
// 1. Check cache first
|
// 1. Check cache first
|
||||||
const db = (cacheStore as any).db;
|
const db = (cacheStore as any).db;
|
||||||
if (db) {
|
if (db) {
|
||||||
const objRow = await db.queryOne<{
|
const typedDb = db as DatabaseAdapter;
|
||||||
|
const objRow = await typedDb.queryOne<{
|
||||||
id: string;
|
id: string;
|
||||||
object_type_name: string;
|
object_type_name: string;
|
||||||
}>(`
|
}>(`
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import { normalizedCacheStore } from './normalizedCacheStore.js';
|
|||||||
import { jiraAssetsClient } from './jiraAssetsClient.js';
|
import { jiraAssetsClient } from './jiraAssetsClient.js';
|
||||||
import { jiraAssetsService } from './jiraAssets.js';
|
import { jiraAssetsService } from './jiraAssets.js';
|
||||||
import { logger } from './logger.js';
|
import { logger } from './logger.js';
|
||||||
|
import type { DatabaseAdapter } from './database/interface.js';
|
||||||
import type {
|
import type {
|
||||||
ApplicationComponent,
|
ApplicationComponent,
|
||||||
IctGovernanceModel,
|
IctGovernanceModel,
|
||||||
@@ -126,7 +127,8 @@ async function getDescriptionFromDatabase(objectId: string): Promise<string | nu
|
|||||||
const descriptionFieldNames = ['description', 'Description', 'DESCRIPTION'];
|
const descriptionFieldNames = ['description', 'Description', 'DESCRIPTION'];
|
||||||
|
|
||||||
// First, get the object to find its type
|
// First, get the object to find its type
|
||||||
const objRow = await db.queryOne<{ object_type_name: string }>(`
|
const typedDb = db as DatabaseAdapter;
|
||||||
|
const objRow = await typedDb.queryOne<{ object_type_name: string }>(`
|
||||||
SELECT object_type_name FROM objects WHERE id = ?
|
SELECT object_type_name FROM objects WHERE id = ?
|
||||||
`, [objectId]);
|
`, [objectId]);
|
||||||
|
|
||||||
@@ -134,7 +136,7 @@ async function getDescriptionFromDatabase(objectId: string): Promise<string | nu
|
|||||||
|
|
||||||
// Try each possible description field name
|
// Try each possible description field name
|
||||||
for (const fieldName of descriptionFieldNames) {
|
for (const fieldName of descriptionFieldNames) {
|
||||||
const descRow = await db.queryOne<{ text_value: string }>(`
|
const descRow = await typedDb.queryOne<{ text_value: string }>(`
|
||||||
SELECT av.text_value
|
SELECT av.text_value
|
||||||
FROM attribute_values av
|
FROM attribute_values av
|
||||||
JOIN attributes a ON av.attribute_id = a.id
|
JOIN attributes a ON av.attribute_id = a.id
|
||||||
@@ -173,7 +175,8 @@ async function toReferenceValue(ref: ObjectReference | null | undefined): Promis
|
|||||||
await db.ensureInitialized?.();
|
await db.ensureInitialized?.();
|
||||||
|
|
||||||
// Get basic object info from database
|
// Get basic object info from database
|
||||||
const objRow = await db.queryOne<{
|
const typedDb = db as DatabaseAdapter;
|
||||||
|
const objRow = await typedDb.queryOne<{
|
||||||
id: string;
|
id: string;
|
||||||
object_key: string;
|
object_key: string;
|
||||||
label: string;
|
label: string;
|
||||||
|
|||||||
@@ -7,14 +7,15 @@
|
|||||||
|
|
||||||
import { logger } from '../logger.js';
|
import { logger } from '../logger.js';
|
||||||
import { normalizedCacheStore } from '../normalizedCacheStore.js';
|
import { normalizedCacheStore } from '../normalizedCacheStore.js';
|
||||||
|
import type { DatabaseAdapter } from './interface.js';
|
||||||
|
|
||||||
export async function fixObjectTypesConstraints(): Promise<void> {
|
export async function fixObjectTypesConstraints(): Promise<void> {
|
||||||
const db = (normalizedCacheStore as any).db;
|
const db = (normalizedCacheStore as any).db as DatabaseAdapter;
|
||||||
if (!db) {
|
if (!db) {
|
||||||
throw new Error('Database not available');
|
throw new Error('Database not available');
|
||||||
}
|
}
|
||||||
|
|
||||||
await db.ensureInitialized?.();
|
await (db as any).ensureInitialized?.();
|
||||||
|
|
||||||
logger.info('Migration: Fixing UNIQUE constraints on object_types table...');
|
logger.info('Migration: Fixing UNIQUE constraints on object_types table...');
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import type {
|
|||||||
TeamDashboardData,
|
TeamDashboardData,
|
||||||
} from '../types/index.js';
|
} from '../types/index.js';
|
||||||
import type { CMDBObjectTypeName } from '../generated/jira-types.js';
|
import type { CMDBObjectTypeName } from '../generated/jira-types.js';
|
||||||
|
import type { DatabaseAdapter } from './database/interface.js';
|
||||||
|
|
||||||
// Attribute name mappings (these should match your Jira Assets schema)
|
// Attribute name mappings (these should match your Jira Assets schema)
|
||||||
const ATTRIBUTE_NAMES = {
|
const ATTRIBUTE_NAMES = {
|
||||||
@@ -126,7 +127,8 @@ class JiraAssetsService {
|
|||||||
if (!db) return null;
|
if (!db) return null;
|
||||||
|
|
||||||
await db.ensureInitialized?.();
|
await db.ensureInitialized?.();
|
||||||
const schemaRow = await db.queryOne<{ jira_schema_id: string }>(
|
const typedDb = db as DatabaseAdapter;
|
||||||
|
const schemaRow = await typedDb.queryOne<{ jira_schema_id: string }>(
|
||||||
`SELECT jira_schema_id FROM schemas ORDER BY jira_schema_id LIMIT 1`
|
`SELECT jira_schema_id FROM schemas ORDER BY jira_schema_id LIMIT 1`
|
||||||
);
|
);
|
||||||
return schemaRow?.jira_schema_id || null;
|
return schemaRow?.jira_schema_id || null;
|
||||||
@@ -146,9 +148,10 @@ class JiraAssetsService {
|
|||||||
if (!db) return [];
|
if (!db) return [];
|
||||||
|
|
||||||
await db.ensureInitialized?.();
|
await db.ensureInitialized?.();
|
||||||
const schemaRows = await db.query<{ jira_schema_id: string }>(
|
const typedDb = db as DatabaseAdapter;
|
||||||
|
const schemaRows = await typedDb.query<{ jira_schema_id: string }>(
|
||||||
`SELECT DISTINCT jira_schema_id FROM schemas WHERE search_enabled = ? ORDER BY jira_schema_id`,
|
`SELECT DISTINCT jira_schema_id FROM schemas WHERE search_enabled = ? ORDER BY jira_schema_id`,
|
||||||
[db.isPostgres ? true : 1]
|
[typedDb.isPostgres ? true : 1]
|
||||||
);
|
);
|
||||||
return schemaRows.map((row: { jira_schema_id: string }) => row.jira_schema_id);
|
return schemaRows.map((row: { jira_schema_id: string }) => row.jira_schema_id);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { logger } from './logger.js';
|
|||||||
import { normalizedCacheStore } from './normalizedCacheStore.js';
|
import { normalizedCacheStore } from './normalizedCacheStore.js';
|
||||||
import { config } from '../config/env.js';
|
import { config } from '../config/env.js';
|
||||||
import type { CMDBObjectTypeName } from '../generated/jira-types.js';
|
import type { CMDBObjectTypeName } from '../generated/jira-types.js';
|
||||||
|
import type { DatabaseAdapter } from './database/interface.js';
|
||||||
|
|
||||||
export interface SchemaMapping {
|
export interface SchemaMapping {
|
||||||
objectTypeName: string;
|
objectTypeName: string;
|
||||||
@@ -61,7 +62,8 @@ class SchemaMappingService {
|
|||||||
|
|
||||||
await db.ensureInitialized?.();
|
await db.ensureInitialized?.();
|
||||||
|
|
||||||
const rows = await db.query<{
|
const typedDb = db as DatabaseAdapter;
|
||||||
|
const rows = await typedDb.query<{
|
||||||
object_type_name: string;
|
object_type_name: string;
|
||||||
schema_id: string;
|
schema_id: string;
|
||||||
enabled: boolean | number;
|
enabled: boolean | number;
|
||||||
@@ -158,7 +160,8 @@ class SchemaMappingService {
|
|||||||
const db = (normalizedCacheStore as any).db;
|
const db = (normalizedCacheStore as any).db;
|
||||||
if (db) {
|
if (db) {
|
||||||
await db.ensureInitialized?.();
|
await db.ensureInitialized?.();
|
||||||
const row = await db.queryOne<{ enabled: boolean | number }>(`
|
const typedDb = db as DatabaseAdapter;
|
||||||
|
const row = await typedDb.queryOne<{ enabled: boolean | number }>(`
|
||||||
SELECT enabled FROM schema_mappings WHERE object_type_name = ?
|
SELECT enabled FROM schema_mappings WHERE object_type_name = ?
|
||||||
`, [objectTypeName]);
|
`, [objectTypeName]);
|
||||||
|
|
||||||
@@ -195,7 +198,8 @@ class SchemaMappingService {
|
|||||||
await db.ensureInitialized?.();
|
await db.ensureInitialized?.();
|
||||||
|
|
||||||
// Use parameterized query to avoid boolean/integer comparison issues
|
// Use parameterized query to avoid boolean/integer comparison issues
|
||||||
const rows = await db.query<{
|
const typedDb = db as DatabaseAdapter;
|
||||||
|
const rows = await typedDb.query<{
|
||||||
object_type_name: string;
|
object_type_name: string;
|
||||||
schema_id: string;
|
schema_id: string;
|
||||||
enabled: boolean | number;
|
enabled: boolean | number;
|
||||||
@@ -243,7 +247,8 @@ class SchemaMappingService {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Get all object types with their mappings
|
// Get all object types with their mappings
|
||||||
const rows = await db.query<{
|
const typedDb = db as DatabaseAdapter;
|
||||||
|
const rows = await typedDb.query<{
|
||||||
type_name: string;
|
type_name: string;
|
||||||
display_name: string;
|
display_name: string;
|
||||||
description: string | null;
|
description: string | null;
|
||||||
@@ -274,7 +279,8 @@ class SchemaMappingService {
|
|||||||
const db = (normalizedCacheStore as any).db;
|
const db = (normalizedCacheStore as any).db;
|
||||||
if (db) {
|
if (db) {
|
||||||
await db.ensureInitialized?.();
|
await db.ensureInitialized?.();
|
||||||
const schemaRow = await db.queryOne<{ jira_schema_id: string }>(
|
const typedDb = db as DatabaseAdapter;
|
||||||
|
const schemaRow = await typedDb.queryOne<{ jira_schema_id: string }>(
|
||||||
`SELECT jira_schema_id FROM schemas ORDER BY jira_schema_id LIMIT 1`
|
`SELECT jira_schema_id FROM schemas ORDER BY jira_schema_id LIMIT 1`
|
||||||
);
|
);
|
||||||
defaultSchemaId = schemaRow?.jira_schema_id || null;
|
defaultSchemaId = schemaRow?.jira_schema_id || null;
|
||||||
@@ -283,7 +289,7 @@ class SchemaMappingService {
|
|||||||
logger.warn('SchemaMapping: Failed to get default schema ID from database', error);
|
logger.warn('SchemaMapping: Failed to get default schema ID from database', error);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rows.map((row: { type_name: string; display_name: string; description: string | null; schema_id: string; enabled: boolean | number; created_at: string; updated_at: string }) => ({
|
return rows.map((row: { type_name: string; display_name: string; description: string | null; object_count: number; sync_priority: number; schema_id: string | null; enabled: number | boolean | null }) => ({
|
||||||
typeName: row.type_name,
|
typeName: row.type_name,
|
||||||
displayName: row.display_name,
|
displayName: row.display_name,
|
||||||
description: row.description,
|
description: row.description,
|
||||||
@@ -291,8 +297,8 @@ class SchemaMappingService {
|
|||||||
enabled: row.enabled === null
|
enabled: row.enabled === null
|
||||||
? true // Default: enabled if no mapping exists
|
? true // Default: enabled if no mapping exists
|
||||||
: (typeof row.enabled === 'boolean' ? row.enabled : row.enabled === 1),
|
: (typeof row.enabled === 'boolean' ? row.enabled : row.enabled === 1),
|
||||||
objectCount: (row as any).object_count || 0,
|
objectCount: row.object_count || 0,
|
||||||
syncPriority: (row as any).sync_priority || 0,
|
syncPriority: row.sync_priority || 0,
|
||||||
}));
|
}));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('SchemaMappingService: Failed to get object types with config', error);
|
logger.error('SchemaMappingService: Failed to get object types with config', error);
|
||||||
@@ -312,7 +318,8 @@ class SchemaMappingService {
|
|||||||
await db.ensureInitialized?.();
|
await db.ensureInitialized?.();
|
||||||
|
|
||||||
// Check if mapping exists
|
// Check if mapping exists
|
||||||
const existing = await db.queryOne<{ schema_id: string }>(`
|
const typedDb = db as DatabaseAdapter;
|
||||||
|
const existing = await typedDb.queryOne<{ schema_id: string }>(`
|
||||||
SELECT schema_id FROM schema_mappings WHERE object_type_name = ?
|
SELECT schema_id FROM schema_mappings WHERE object_type_name = ?
|
||||||
`, [objectTypeName]);
|
`, [objectTypeName]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user