Skip to content

Commit 641a0b5

Browse files
authored
Merge pull request #1803 from rocket-admin/backend_typescript_improvements
Backend typescript improvements
2 parents 4d3e905 + dfc7fc0 commit 641a0b5

63 files changed

Lines changed: 235 additions & 145 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/code-quality.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,6 @@ jobs:
4040
- name: Run Biome
4141
if: steps.changed.outputs.files != ''
4242
run: biome ci --formatter-enabled=false --assist-enabled=false ${{ steps.changed.outputs.files }}
43+
- name: Typecheck backend
44+
if: steps.changed.outputs.files != ''
45+
run: pnpm --filter ./backend typecheck

backend/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
"scripts": {
1010
"prebuild": "rimraf dist",
1111
"build": "nest build",
12+
"typecheck": "tsc --noEmit --incremental false -p tsconfig.src.json && tsc --noEmit --incremental false -p tsconfig.json",
13+
"lint": "biome lint src test",
1214
"start": "nest start",
1315
"start:dev": "nest start --watch --preserveWatchOutput",
1416
"start:debug": "nest start --debug --watch",

backend/src/entities/ai/ai.service.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { cleanAIJsonResponse } from '../../ai-core/tools/query-validators.js';
55
import { QueryOrderingEnum } from '../../enums/query-ordering.enum.js';
66
import { WidgetTypeEnum } from '../../enums/widget-type.enum.js';
77
import { checkFieldAutoincrement } from '../../helpers/check-field-autoincrement.js';
8+
import { getErrorMessage } from '../../helpers/get-error-message.js';
89
import { TableSettingsEntity } from '../table-settings/common-table-settings/table-settings.entity.js';
910
import { TableWidgetEntity } from '../widget/table-widget.entity.js';
1011
import { TableInformation } from './ai-data-entities/types/ai-module-types.js';
@@ -78,13 +79,13 @@ export class AiService {
7879
const batchSettings = await this.processTablesBatch(batch);
7980
allSettings.push(...batchSettings);
8081
} catch (error) {
81-
console.warn(`Batch processing failed, falling back to individual table processing: ${error.message}`);
82+
console.warn(`Batch processing failed, falling back to individual table processing: ${getErrorMessage(error)}`);
8283
for (const tableInfo of batch) {
8384
try {
8485
const singleTableSettings = await this.processTablesBatch([tableInfo]);
8586
allSettings.push(...singleTableSettings);
8687
} catch (singleError) {
87-
console.error(`Error processing AI for table "${tableInfo.table_name}": ${singleError.message}`);
88+
console.error(`Error processing AI for table "${tableInfo.table_name}": ${getErrorMessage(singleError)}`);
8889
}
8990
}
9091
}
@@ -289,7 +290,7 @@ IMPORTANT:
289290
try {
290291
return JSON.parse(cleanedResponse) as AIResponse;
291292
} catch (error) {
292-
throw new Error(`Failed to parse AI response for tables [${tableNames.join(', ')}]: ${error.message}`);
293+
throw new Error(`Failed to parse AI response for tables [${tableNames.join(', ')}]: ${getErrorMessage(error)}`);
293294
}
294295
}
295296

backend/src/entities/ai/use-cases/request-info-from-table-with-ai-v7.use.case.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export class RequestInfoFromTableWithAIUseCaseV7
115115

116116
response.end();
117117
} catch (error) {
118-
await slackPostMessage(error?.message);
118+
await slackPostMessage((error as Error)?.message);
119119
Sentry.captureException(error);
120120
if (!response.headersSent) {
121121
response.status(500).send({ error: 'An error occurred while processing your request.' });
@@ -192,7 +192,7 @@ export class RequestInfoFromTableWithAIUseCaseV7
192192

193193
depth++;
194194
} catch (loopError) {
195-
this.logger.error(`Error in tool loop at depth ${depth + 1}: ${loopError.message}`);
195+
this.logger.error(`Error in tool loop at depth ${depth + 1}: ${(loopError as Error).message}`);
196196
throw loopError;
197197
}
198198
}
@@ -290,8 +290,9 @@ export class RequestInfoFromTableWithAIUseCaseV7
290290
result = encodeError({ error: `Unknown tool: ${toolCall.name}` });
291291
}
292292
} catch (error) {
293-
this.logger.error(`Tool call ${toolCall.name} (${toolCall.id}) failed: ${error.message}`);
294-
result = encodeError({ error: error.message });
293+
const errMessage = (error as Error).message;
294+
this.logger.error(`Tool call ${toolCall.name} (${toolCall.id}) failed: ${errMessage}`);
295+
result = encodeError({ error: errMessage });
295296
}
296297

297298
results.push({ toolCallId: toolCall.id, result });

backend/src/entities/cedar-authorization/cedar-authorization.service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export class CedarAuthorizationService implements ICedarAuthorizationService, On
185185
resource: { type: 'RocketAdmin::Connection', id: 'test' },
186186
context: {},
187187
policies: { staticPolicies: 'permit(principal, action, resource);' },
188-
entities: [],
188+
entities: [] as unknown[],
189189
schema: schema,
190190
};
191191
const result = cedarWasm.isAuthorized(testCall as Parameters<typeof cedarWasm.isAuthorized>[0]);
@@ -198,7 +198,7 @@ export class CedarAuthorizationService implements ICedarAuthorizationService, On
198198
}
199199
} catch (e) {
200200
if (e instanceof HttpException) throw e;
201-
throw new HttpException({ message: `Invalid cedar schema: ${e.message}` }, HttpStatus.BAD_REQUEST);
201+
throw new HttpException({ message: `Invalid cedar schema: ${(e as Error).message}` }, HttpStatus.BAD_REQUEST);
202202
}
203203
}
204204

@@ -291,12 +291,12 @@ export class CedarAuthorizationService implements ICedarAuthorizationService, On
291291
resource: { type: 'RocketAdmin::Connection', id: 'test' },
292292
context: {},
293293
policies: { staticPolicies: policyText },
294-
entities: [],
294+
entities: [] as unknown[],
295295
schema: this.schema,
296296
};
297297
cedarWasm.isAuthorized(testCall as Parameters<typeof cedarWasm.isAuthorized>[0]);
298298
} catch (e) {
299-
throw new HttpException({ message: `Invalid cedar policy: ${e.message}` }, HttpStatus.BAD_REQUEST);
299+
throw new HttpException({ message: `Invalid cedar policy: ${(e as Error).message}` }, HttpStatus.BAD_REQUEST);
300300
}
301301
}
302302

backend/src/entities/cedar-authorization/cedar-schema.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export const CEDAR_SCHEMA = {
22
RocketAdmin: {
33
entityTypes: {
44
User: {
5-
memberOfTypes: [],
5+
memberOfTypes: [] as string[],
66
shape: {
77
type: 'Record',
88
attributes: {
@@ -11,7 +11,7 @@ export const CEDAR_SCHEMA = {
1111
},
1212
},
1313
Group: {
14-
memberOfTypes: [],
14+
memberOfTypes: [] as string[],
1515
shape: {
1616
type: 'Record',
1717
attributes: {
@@ -21,7 +21,7 @@ export const CEDAR_SCHEMA = {
2121
},
2222
},
2323
Connection: {
24-
memberOfTypes: [],
24+
memberOfTypes: [] as string[],
2525
shape: {
2626
type: 'Record',
2727
attributes: {},

backend/src/entities/connection/use-cases/find-all-connections.use.case.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export class FindAllConnectionsUseCase
110110
return Object.keys(connection).reduce((acc, key) => {
111111
if (allowedKeys.includes(key)) {
112112
// eslint-disable-next-line security/detect-object-injection
113-
acc[key] = connection[key];
113+
(acc as Record<string, unknown>)[key] = (connection as unknown as Record<string, unknown>)[key];
114114
}
115115
return acc;
116116
}, {} as FilteredConnection);

backend/src/entities/connection/use-cases/find-one-connection.use.case.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class FindOneConnectionUseCase
6767
return Object.keys(connection).reduce((acc, key) => {
6868
if (allowedKeys.includes(key)) {
6969
// eslint-disable-next-line security/detect-object-injection
70-
acc[key] = connection[key];
70+
(acc as Record<string, unknown>)[key] = (connection as unknown as Record<string, unknown>)[key];
7171
}
7272
return acc;
7373
}, {} as FilteredConnection);

backend/src/entities/connection/use-cases/get-connection-diagram.use.case.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class GetConnectionDiagramUseCase
5252
try {
5353
tables = await dao.getTablesFromDB(userEmail);
5454
} catch (e) {
55-
throw new UnknownSQLException(e.message, ExceptionOperations.FAILED_TO_GET_TABLES);
55+
throw new UnknownSQLException((e as Error).message, ExceptionOperations.FAILED_TO_GET_TABLES);
5656
}
5757

5858
const realTables = tables.filter((t) => !t.isView);

backend/src/entities/connection/use-cases/preview-connection-diagram.use.case.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export class PreviewConnectionDiagramUseCase
5353
try {
5454
tables = await dao.getTablesFromDB(userEmail);
5555
} catch (e) {
56-
throw new UnknownSQLException(e.message, ExceptionOperations.FAILED_TO_GET_TABLES);
56+
throw new UnknownSQLException((e as Error).message, ExceptionOperations.FAILED_TO_GET_TABLES);
5757
}
5858

5959
const realTables = tables.filter((t) => !t.isView);

0 commit comments

Comments
 (0)