From 25d2f8fef9b02c9f2a5ca5b39a3b7e17e0c29edf Mon Sep 17 00:00:00 2001 From: Artem Niehrieiev Date: Thu, 30 Apr 2026 08:58:27 +0000 Subject: [PATCH 1/3] refactor: remove unused delete personal table settings functionality Co-authored-by: Copilot --- .../personal-table-settings.controller.ts | 36 ------------------ .../personal-table-settings.module.ts | 5 --- ...delete-personal-table-settings.use.case.ts | 37 ------------------- 3 files changed, 78 deletions(-) delete mode 100644 backend/src/entities/table-settings/personal-table-settings/use-cases/delete-personal-table-settings.use.case.ts diff --git a/backend/src/entities/table-settings/personal-table-settings/personal-table-settings.controller.ts b/backend/src/entities/table-settings/personal-table-settings/personal-table-settings.controller.ts index 8797c5585..c2022904a 100644 --- a/backend/src/entities/table-settings/personal-table-settings/personal-table-settings.controller.ts +++ b/backend/src/entities/table-settings/personal-table-settings/personal-table-settings.controller.ts @@ -28,7 +28,6 @@ import { CreatePersonalTableSettingsDto } from './dto/create-personal-table-sett import { FoundPersonalTableSettingsDto } from './dto/found-personal-table-settings.dto.js'; import { ICreateUpdatePersonalTableSettings, - IDeletePersonalTableSettings, IFindPersonalTableSettings, } from './use-cases/personal-table-settings.use-cases.interface.js'; @@ -44,8 +43,6 @@ export class PersonalTableSettingsController { private readonly findPersonalTableSettingsUseCase: IFindPersonalTableSettings, @Inject(UseCaseType.CREATE_UPDATE_PERSONAL_TABLE_SETTINGS) private readonly createUpdatePersonalTableSettingsUseCase: ICreateUpdatePersonalTableSettings, - @Inject(UseCaseType.DELETE_PERSONAL_TABLE_SETTINGS) - private readonly deletePersonalTableSettingsUseCase: IDeletePersonalTableSettings, ) {} @ApiOperation({ summary: 'Find user personal table settings' }) @@ -125,37 +122,4 @@ export class PersonalTableSettingsController { }; return await this.createUpdatePersonalTableSettingsUseCase.execute(inputData, InTransactionEnum.OFF); } - - @ApiOperation({ summary: 'Clear user personal table settings' }) - @ApiResponse({ - status: 200, - description: 'Table settings removed.', - type: FoundPersonalTableSettingsDto, - }) - @ApiParam({ name: 'connectionId', required: true }) - @ApiQuery({ name: 'tableName', required: true }) - @UseGuards(TableReadGuard) - @Delete('/settings/personal/:connectionId') - async clearTableSettings( - @SlugUuid('connectionId') connectionId: string, - @QueryTableName() tableName: string, - @MasterPassword() masterPwd: string, - @UserId() userId: string, - ): Promise { - if (!connectionId) { - throw new HttpException( - { - message: Messages.CONNECTION_ID_MISSING, - }, - HttpStatus.BAD_REQUEST, - ); - } - const inputData: FindPersonalTableSettingsDs = { - connectionId, - tableName, - userId, - masterPassword: masterPwd, - }; - return await this.deletePersonalTableSettingsUseCase.execute(inputData, InTransactionEnum.OFF); - } } diff --git a/backend/src/entities/table-settings/personal-table-settings/personal-table-settings.module.ts b/backend/src/entities/table-settings/personal-table-settings/personal-table-settings.module.ts index 0fc53f8ff..069274893 100644 --- a/backend/src/entities/table-settings/personal-table-settings/personal-table-settings.module.ts +++ b/backend/src/entities/table-settings/personal-table-settings/personal-table-settings.module.ts @@ -24,10 +24,6 @@ import { FindPersonalTableSettingsUseCase } from './use-cases/find-personal-tabl provide: UseCaseType.CREATE_UPDATE_PERSONAL_TABLE_SETTINGS, useClass: CreateUpdatePersonalTableSettingsUseCase, }, - { - provide: UseCaseType.DELETE_PERSONAL_TABLE_SETTINGS, - useClass: CreateUpdatePersonalTableSettingsUseCase, - }, ], controllers: [PersonalTableSettingsController], exports: [], @@ -39,7 +35,6 @@ export class PersonalTableSettingsModule { .forRoutes( { path: '/settings/personal/:connectionId', method: RequestMethod.GET }, { path: '/settings/personal/:connectionId', method: RequestMethod.PUT }, - { path: '/settings/personal/:connectionId', method: RequestMethod.DELETE }, ); } } diff --git a/backend/src/entities/table-settings/personal-table-settings/use-cases/delete-personal-table-settings.use.case.ts b/backend/src/entities/table-settings/personal-table-settings/use-cases/delete-personal-table-settings.use.case.ts deleted file mode 100644 index 64ce1bcfe..000000000 --- a/backend/src/entities/table-settings/personal-table-settings/use-cases/delete-personal-table-settings.use.case.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { Inject, Injectable, Scope } from '@nestjs/common'; -import AbstractUseCase from '../../../../common/abstract-use.case.js'; -import { IGlobalDatabaseContext } from '../../../../common/application/global-database-context.interface.js'; -import { BaseType } from '../../../../common/data-injection.tokens.js'; -import { FindPersonalTableSettingsDs } from '../data-structures/find-personal-table-settings.ds.js'; -import { FoundPersonalTableSettingsDto } from '../dto/found-personal-table-settings.dto.js'; -import { buildFoundTableSettingsDto } from '../utils/build-found-table-settings-dto.js'; -import { IDeletePersonalTableSettings } from './personal-table-settings.use-cases.interface.js'; - -@Injectable({ scope: Scope.REQUEST }) -export class DeletePersonalTableSettingsUseCase - extends AbstractUseCase - implements IDeletePersonalTableSettings -{ - constructor( - @Inject(BaseType.GLOBAL_DB_CONTEXT) - protected _dbContext: IGlobalDatabaseContext, - ) { - super(); - } - - public async implementation(inputData: FindPersonalTableSettingsDs): Promise { - const { connectionId, userId, tableName } = inputData; - - const foundPersonalTableSettings = await this._dbContext.personalTableSettingsRepository.findUserTableSettings( - connectionId, - tableName, - userId, - ); - - if (foundPersonalTableSettings) { - await this._dbContext.personalTableSettingsRepository.remove(foundPersonalTableSettings); - } - - return buildFoundTableSettingsDto(foundPersonalTableSettings); - } -} From aaf4d670906c9e5985a7f6a1227299cef6090b68 Mon Sep 17 00:00:00 2001 From: Artem Niehrieiev Date: Thu, 30 Apr 2026 09:05:20 +0000 Subject: [PATCH 2/3] refactor: remove unused table analysis and settings functions --- backend/src/ai-core/tools/database-tools.ts | 24 -------- backend/src/ai-core/tools/prompts.ts | 57 ------------------- backend/src/ai-core/tools/query-validators.ts | 30 ---------- backend/src/ai-core/utils/message-builder.ts | 4 -- .../helpers/app/get-requeired-env-variable.ts | 5 -- 5 files changed, 120 deletions(-) diff --git a/backend/src/ai-core/tools/database-tools.ts b/backend/src/ai-core/tools/database-tools.ts index 6c683e699..18f8bb043 100644 --- a/backend/src/ai-core/tools/database-tools.ts +++ b/backend/src/ai-core/tools/database-tools.ts @@ -95,27 +95,3 @@ export function createDashboardGenerationTools(): AIToolDefinition[] { }, ]; } - -export function createTableAnalysisTools(): AIToolDefinition[] { - return [ - { - name: 'analyzeTableSchema', - description: 'Analyzes a table schema and returns recommendations for display settings and widgets.', - parameters: { - type: 'object', - properties: { - tableName: { - type: 'string', - description: 'The name of the table to analyze.', - }, - columns: { - type: 'array', - description: 'Array of column definitions with name, type, and constraints.', - }, - }, - required: ['tableName', 'columns'], - additionalProperties: false, - }, - }, - ]; -} diff --git a/backend/src/ai-core/tools/prompts.ts b/backend/src/ai-core/tools/prompts.ts index 6383613e7..b0f7081fe 100644 --- a/backend/src/ai-core/tools/prompts.ts +++ b/backend/src/ai-core/tools/prompts.ts @@ -37,63 +37,6 @@ IMPORTANT: Remember that all responses should be clear and user-friendly, explaining technical details when necessary.`; } -export function createTableSettingsSystemPrompt(widgetTypes: string[]): string { - return `You are a database administration assistant. Analyze the following database tables and generate optimal settings for displaying and managing them in a web admin panel. - -For each table, provide: -1. display_name: A human-readable name for the table -2. search_fields: Columns that should be searchable (text fields like name, email, title) -3. readonly_fields: Columns that should not be editable (like auto_increment, timestamps) -4. columns_view: All columns in preferred display order -5. widgets: For each column, suggest the best widget type from: ${widgetTypes.join(', ')} - -Available widget types and when to use them: -- Password: for password fields -- Boolean: for boolean/bit columns -- Date: for date columns -- Time: for time-only columns -- DateTime: for datetime/timestamp columns -- JSON: for JSON/JSONB columns -- Textarea: for long text fields (description, content, etc.) -- String: for short text fields (name, title, etc.) -- Readonly: for auto-generated fields -- Number: for numeric columns -- Select: for columns with limited options -- UUID: for UUID columns -- Enum: for enum columns -- Foreign_key: for foreign key columns -- File: for file path columns -- Image: for image URL columns -- URL: for URL columns -- Code: for code snippets -- Phone: for phone number columns -- Country: for country columns -- Color: for color columns (hex values) -- Range: for range values -- Timezone: for timezone columns - -Respond ONLY with valid JSON in this exact format (no markdown, no explanations): -{ - "tables": [ - { - "table_name": "table_name", - "display_name": "Human Readable Name", - "search_fields": ["name", "email"], - "readonly_fields": ["id", "created_at"], - "columns_view": ["id", "name", "email", "created_at"], - "widgets": [ - { - "field_name": "column_name", - "widget_type": "String", - "name": "Column Display Name", - "description": "Description of what this column contains" - } - ] - } - ] -}`; -} - export function convertDbTypeToReadableString(dataType: ConnectionTypesEnum): string { switch (dataType) { case ConnectionTypesEnum.postgres: diff --git a/backend/src/ai-core/tools/query-validators.ts b/backend/src/ai-core/tools/query-validators.ts index bed85dd49..c088144a1 100644 --- a/backend/src/ai-core/tools/query-validators.ts +++ b/backend/src/ai-core/tools/query-validators.ts @@ -67,36 +67,6 @@ export function wrapQueryWithLimit(query: string, databaseType: ConnectionTypesE } } -export function sanitizeJsonString(jsonStr: string): string { - try { - JSON.parse(jsonStr); - return jsonStr; - } catch (_e) { - const startBrace = jsonStr.indexOf('{'); - if (startBrace === -1) { - return '{}'; - } - - const endBrace = jsonStr.lastIndexOf('}'); - if (endBrace === -1 || endBrace <= startBrace) { - return '{}'; - } - - let possibleJson = jsonStr.substring(startBrace, endBrace + 1); - - possibleJson = possibleJson.replace(/,\s*}/g, '}'); - possibleJson = possibleJson.replace(/,\s*]/g, ']'); - - try { - JSON.parse(possibleJson); - return possibleJson; - } catch (_parseErr) { - console.error('Could not sanitize JSON, returning empty object'); - return '{}'; - } - } -} - export function cleanAIJsonResponse(response: string): string { let cleanedResponse = response.trim(); if (cleanedResponse.startsWith('```json')) { diff --git a/backend/src/ai-core/utils/message-builder.ts b/backend/src/ai-core/utils/message-builder.ts index 10b431117..24b9f4acd 100644 --- a/backend/src/ai-core/utils/message-builder.ts +++ b/backend/src/ai-core/utils/message-builder.ts @@ -64,8 +64,4 @@ export class MessageBuilder { } } -export function createSimpleMessages(systemPrompt: string, userMessage: string): BaseMessage[] { - return new MessageBuilder().system(systemPrompt).human(userMessage).build(); -} - export { HumanMessage, SystemMessage, AIMessage, ToolMessage, BaseMessage }; diff --git a/backend/src/helpers/app/get-requeired-env-variable.ts b/backend/src/helpers/app/get-requeired-env-variable.ts index 0c62a5b77..e27e6a7e6 100644 --- a/backend/src/helpers/app/get-requeired-env-variable.ts +++ b/backend/src/helpers/app/get-requeired-env-variable.ts @@ -6,8 +6,3 @@ export function getRequiredEnvVariable(variableName: string): string { } return variableValue; } - -export function getOptionalEnvVariable(variableName: string): string | undefined { - // eslint-disable-next-line security/detect-object-injection - return process.env[variableName]; -} From f4dd4ca3c2e79a85b64e08b7252c04e475774344 Mon Sep 17 00:00:00 2001 From: Artem Niehrieiev Date: Thu, 30 Apr 2026 12:34:16 +0000 Subject: [PATCH 3/3] refactor: remove unused personal table settings functionality and helper --- backend/src/common/data-injection.tokens.ts | 1 - .../personal-table-settings.use-cases.interface.ts | 7 ------- backend/src/helpers/get-master-password.ts | 6 ------ backend/src/helpers/index.ts | 1 - 4 files changed, 15 deletions(-) delete mode 100644 backend/src/helpers/get-master-password.ts diff --git a/backend/src/common/data-injection.tokens.ts b/backend/src/common/data-injection.tokens.ts index 79804b05a..972ecb321 100644 --- a/backend/src/common/data-injection.tokens.ts +++ b/backend/src/common/data-injection.tokens.ts @@ -76,7 +76,6 @@ export enum UseCaseType { FIND_PERSONAL_TABLE_SETTINGS = 'FIND_PERSONAL_TABLE_SETTINGS', CREATE_UPDATE_PERSONAL_TABLE_SETTINGS = 'CREATE_UPDATE_PERSONAL_TABLE_SETTINGS', - DELETE_PERSONAL_TABLE_SETTINGS = 'DELETE_PERSONAL_TABLE_SETTINGS', GET_HELLO = 'GET_HELLO', diff --git a/backend/src/entities/table-settings/personal-table-settings/use-cases/personal-table-settings.use-cases.interface.ts b/backend/src/entities/table-settings/personal-table-settings/use-cases/personal-table-settings.use-cases.interface.ts index 6455a0fb7..a7f707849 100644 --- a/backend/src/entities/table-settings/personal-table-settings/use-cases/personal-table-settings.use-cases.interface.ts +++ b/backend/src/entities/table-settings/personal-table-settings/use-cases/personal-table-settings.use-cases.interface.ts @@ -16,10 +16,3 @@ export interface ICreateUpdatePersonalTableSettings { inTransaction: InTransactionEnum, ): Promise; } - -export interface IDeletePersonalTableSettings { - execute( - inputData: FindPersonalTableSettingsDs, - inTransaction: InTransactionEnum, - ): Promise; -} diff --git a/backend/src/helpers/get-master-password.ts b/backend/src/helpers/get-master-password.ts deleted file mode 100644 index 89fedbcdb..000000000 --- a/backend/src/helpers/get-master-password.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { IRequestWithCognitoInfo } from '../authorization/index.js'; - -export function getMasterPwd(request: IRequestWithCognitoInfo): string | null { - const masterPwd = request.headers.masterpwd; - return masterPwd ? (masterPwd as string) : null; -} diff --git a/backend/src/helpers/index.ts b/backend/src/helpers/index.ts index 04e30e57b..bfc9e4c1d 100644 --- a/backend/src/helpers/index.ts +++ b/backend/src/helpers/index.ts @@ -1,7 +1,6 @@ export { binaryToHex, isBinary } from './binary-to-hex.js'; export { checkFieldAutoincrement } from './check-field-autoincrement.js'; export { compareArrayElements } from './compare-array-elements.js'; -export { getMasterPwd } from './get-master-password.js'; export { getPropertyValueByDescriptor } from './get-property-value-by-descriptor.js'; export { getUniqArrayStrings } from './get-uniq-array-strings.js'; export { isConnectionEntityAgent, isConnectionTypeAgent } from './is-connection-entity-agent.js';