diff --git a/backend/src/entities/agent/repository/custom-agent-repository-extension.ts b/backend/src/entities/agent/repository/custom-agent-repository-extension.ts index 971da925..96cfb0e5 100644 --- a/backend/src/entities/agent/repository/custom-agent-repository-extension.ts +++ b/backend/src/entities/agent/repository/custom-agent-repository-extension.ts @@ -1,7 +1,7 @@ import { nanoid } from 'nanoid'; import { ConnectionEntity } from '../../connection/connection.entity.js'; import { AgentEntity } from '../agent.entity.js'; -import { ConnectionTypeTestEnum } from '../../../enums/connection-type.enum.js'; +import { ConnectionTypeTestEnum } from '@rocketadmin/shared-code/dist/src/shared/enums/connection-types-enum.js'; export const customAgentRepositoryExtension = { async createNewAgentForConnectionAndReturnToken(connection: ConnectionEntity): Promise { diff --git a/backend/src/entities/ai/use-cases/request-info-from-table-with-ai-v4.use.case.ts b/backend/src/entities/ai/use-cases/request-info-from-table-with-ai-v4.use.case.ts index 0fc967da..ae67d457 100644 --- a/backend/src/entities/ai/use-cases/request-info-from-table-with-ai-v4.use.case.ts +++ b/backend/src/entities/ai/use-cases/request-info-from-table-with-ai-v4.use.case.ts @@ -1,6 +1,5 @@ import { BadRequestException, Inject, Injectable, NotFoundException, Scope } from '@nestjs/common'; import { getDataAccessObject } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/create-data-access-object.js'; -import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/enums/connection-types-enum.js'; import OpenAI from 'openai'; import AbstractUseCase from '../../../common/abstract-use.case.js'; import { IGlobalDatabaseContext } from '../../../common/application/global-database-context.interface.js'; @@ -17,9 +16,10 @@ import { ResponsesModel } from 'openai/resources/index.js'; import { Stream } from 'openai/core/streaming.js'; import { Response } from 'express'; import { ConnectionEntity } from '../../connection/connection.entity.js'; -import { IDataAccessObject } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/interfaces/data-access-object.interface.js'; -import { IDataAccessObjectAgent } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/interfaces/data-access-object-agent.interface.js'; import { AiResponsesToUserEntity } from '../ai-data-entities/ai-reponses-to-user/ai-responses-to-user.entity.js'; +import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/shared/enums/connection-types-enum.js'; +import { IDataAccessObjectAgent } from '@rocketadmin/shared-code/dist/src/shared/interfaces/data-access-object-agent.interface.js'; +import { IDataAccessObject } from '@rocketadmin/shared-code/dist/src/shared/interfaces/data-access-object.interface.js'; @Injectable({ scope: Scope.REQUEST }) export class RequestInfoFromTableWithAIUseCaseV4 extends AbstractUseCase diff --git a/backend/src/entities/connection/application/data-structures/create-connection.ds.ts b/backend/src/entities/connection/application/data-structures/create-connection.ds.ts index 5f3e65c4..ecbf3922 100644 --- a/backend/src/entities/connection/application/data-structures/create-connection.ds.ts +++ b/backend/src/entities/connection/application/data-structures/create-connection.ds.ts @@ -1,4 +1,4 @@ -import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/enums/connection-types-enum.js'; +import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/shared/enums/connection-types-enum.js'; export class CreateConnectionDs { connection_parameters: { diff --git a/backend/src/entities/connection/application/data-structures/found-connections.ds.ts b/backend/src/entities/connection/application/data-structures/found-connections.ds.ts index 6bd95ee9..da7d28fd 100644 --- a/backend/src/entities/connection/application/data-structures/found-connections.ds.ts +++ b/backend/src/entities/connection/application/data-structures/found-connections.ds.ts @@ -1,9 +1,9 @@ import { ApiProperty } from '@nestjs/swagger'; +import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/shared/enums/connection-types-enum.js'; import { AccessLevelEnum } from '../../../../enums/index.js'; -import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/enums/connection-types-enum.js'; -import { UserEntity } from '../../../user/user.entity.js'; import { FoundGroupDataWithUsersDs } from '../../../group/application/data-sctructures/found-user-groups.ds.js'; import { SimpleFoundUserInfoDs } from '../../../user/dto/found-user.dto.js'; +import { UserEntity } from '../../../user/user.entity.js'; export class FoundDirectConnectionsDs { @ApiProperty() diff --git a/backend/src/entities/connection/application/data-structures/update-connection.ds.ts b/backend/src/entities/connection/application/data-structures/update-connection.ds.ts index 1c11182a..88fa4a9b 100644 --- a/backend/src/entities/connection/application/data-structures/update-connection.ds.ts +++ b/backend/src/entities/connection/application/data-structures/update-connection.ds.ts @@ -1,4 +1,4 @@ -import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/enums/connection-types-enum.js'; +import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/shared/enums/connection-types-enum.js'; export class UpdateConnectionDs { connection_parameters: { diff --git a/backend/src/entities/connection/application/dto/create-connection.dto.ts b/backend/src/entities/connection/application/dto/create-connection.dto.ts index dcda5a68..1bdac469 100644 --- a/backend/src/entities/connection/application/dto/create-connection.dto.ts +++ b/backend/src/entities/connection/application/dto/create-connection.dto.ts @@ -1,8 +1,10 @@ import { ApiProperty } from '@nestjs/swagger'; import { IsBoolean, IsEnum, IsNumber, IsOptional, IsString, Max, Min } from 'class-validator'; -import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/enums/connection-types-enum.js'; import { isTest } from '../../../../helpers/app/is-test.js'; -import { ConnectionTypeTestEnum } from '../../../../enums/connection-type.enum.js'; +import { + ConnectionTypesEnum, + ConnectionTypeTestEnum, +} from '@rocketadmin/shared-code/dist/src/shared/enums/connection-types-enum.js'; export class CreateConnectionDto { @ApiProperty({ required: false }) diff --git a/backend/src/entities/connection/application/dto/created-connection.dto.ts b/backend/src/entities/connection/application/dto/created-connection.dto.ts index c0dda9e5..a4b66d8f 100644 --- a/backend/src/entities/connection/application/dto/created-connection.dto.ts +++ b/backend/src/entities/connection/application/dto/created-connection.dto.ts @@ -1,6 +1,6 @@ import { ApiProperty } from '@nestjs/swagger'; -import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/enums/connection-types-enum.js'; import { FoundUserDto } from '../../../user/dto/found-user.dto.js'; +import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/shared/enums/connection-types-enum.js'; export class CreatedGroupInConnectionDTO { @ApiProperty() diff --git a/backend/src/entities/connection/connection.controller.ts b/backend/src/entities/connection/connection.controller.ts index c8077951..b98a0048 100644 --- a/backend/src/entities/connection/connection.controller.ts +++ b/backend/src/entities/connection/connection.controller.ts @@ -42,15 +42,16 @@ import { RestoredConnectionDs } from './application/data-structures/restored-con import { UpdateConnectionDs } from './application/data-structures/update-connection.ds.js'; import { UpdateMasterPasswordDs } from './application/data-structures/update-master-password.ds.js'; import { CreatedConnectionDTO } from './application/dto/created-connection.dto.js'; - import { ApiBearerAuth, ApiBody, ApiOperation, ApiQuery, ApiResponse, ApiTags } from '@nestjs/swagger'; +import { SkipThrottle } from '@nestjs/throttler'; +import { isRedisConnectionUrl } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/create-data-access-object.js'; import { TestConnectionResultDS } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/data-structures/test-result-connection.ds.js'; -import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/enums/connection-types-enum.js'; import { SuccessResponse } from '../../microservices/saas-microservice/data-structures/common-responce.ds.js'; import { FoundGroupResponseDto } from '../group/dto/found-group-response.dto.js'; import { FoundOneConnectionDs } from './application/data-structures/found-one-connection.ds.js'; import { FoundPermissionsInConnectionDs } from './application/data-structures/found-permissions-in-connection.ds.js'; import { ValidateConnectionMasterPasswordDs } from './application/data-structures/validate-connection-master-password.ds.js'; +import { CreateConnectionDto } from './application/dto/create-connection.dto.js'; import { CreateGroupInConnectionDTO } from './application/dto/create-group-in-connection.dto.js'; import { DeleteConnectionReasonDto } from './application/dto/delete-connection.dto.js'; import { DeleteGroupFromConnectionDTO } from './application/dto/delete-group-from-connection-request.dto.js'; @@ -81,9 +82,7 @@ import { } from './use-cases/use-cases.interfaces.js'; import { TokenValidationResult } from './use-cases/validate-connection-token.use.case.js'; import { isTestConnectionUtil } from './utils/is-test-connection-util.js'; -import { SkipThrottle } from '@nestjs/throttler'; -import { isRedisConnectionUrl } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/create-data-access-object.js'; -import { CreateConnectionDto } from './application/dto/create-connection.dto.js'; +import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/shared/enums/connection-types-enum.js'; @UseInterceptors(SentryInterceptor) @Controller() diff --git a/backend/src/entities/connection/use-cases/test-connection.use.case.ts b/backend/src/entities/connection/use-cases/test-connection.use.case.ts index 0f9f67e4..a6214310 100644 --- a/backend/src/entities/connection/use-cases/test-connection.use.case.ts +++ b/backend/src/entities/connection/use-cases/test-connection.use.case.ts @@ -1,24 +1,24 @@ import { Inject, Injectable } from '@nestjs/common'; -import { getRepository } from 'typeorm'; -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 { getDataAccessObject, isRedisConnectionUrl, } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/create-data-access-object.js'; +import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/shared/enums/connection-types-enum.js'; +import { getRepository } from 'typeorm'; +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 { Messages } from '../../../exceptions/text/messages.js'; import { processExceptionMessage } from '../../../exceptions/utils/process-exception-message.js'; -import { isConnectionTypeAgent, slackPostMessage } from '../../../helpers/index.js'; import { Encryptor } from '../../../helpers/encryption/encryptor.js'; +import { isConnectionTypeAgent, slackPostMessage } from '../../../helpers/index.js'; +import { CreateConnectionDs } from '../application/data-structures/create-connection.ds.js'; import { TestConnectionResultDs } from '../application/data-structures/test-connection-result.ds.js'; import { UpdateConnectionDs } from '../application/data-structures/update-connection.ds.js'; import { ConnectionEntity } from '../connection.entity.js'; import { isHostAllowed } from '../utils/is-host-allowed.js'; -import { ITestConnection } from './use-cases.interfaces.js'; import { processAWSConnection } from '../utils/process-aws-connection.util.js'; -import { CreateConnectionDs } from '../application/data-structures/create-connection.ds.js'; -import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/enums/connection-types-enum.js'; +import { ITestConnection } from './use-cases.interfaces.js'; @Injectable() export class TestConnectionUseCase @@ -129,7 +129,11 @@ export class TestConnectionUseCase }; } } else { - if (!connectionData.password && !isConnectionTypeAgent(connectionData.type) && !isRedisConnectionUrl(connectionData.host)) { + if ( + !connectionData.password && + !isConnectionTypeAgent(connectionData.type) && + !isRedisConnectionUrl(connectionData.host) + ) { return { result: false, message: Messages.PASSWORD_MISSING, diff --git a/backend/src/entities/connection/utils/validate-create-connection-data.ts b/backend/src/entities/connection/utils/validate-create-connection-data.ts index 5c3fcba3..eb7e37f3 100644 --- a/backend/src/entities/connection/utils/validate-create-connection-data.ts +++ b/backend/src/entities/connection/utils/validate-create-connection-data.ts @@ -1,9 +1,11 @@ import { HttpStatus } from '@nestjs/common'; import { HttpException } from '@nestjs/common/exceptions/http.exception.js'; -import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/enums/connection-types-enum.js'; +import { + ConnectionTypesEnum, + ConnectionTypeTestEnum, +} from '@rocketadmin/shared-code/dist/src/shared/enums/connection-types-enum.js'; import dns from 'dns'; import ipRangeCheck from 'ip-range-check'; -import { ConnectionTypeTestEnum } from '../../../enums/connection-type.enum.js'; import { Messages } from '../../../exceptions/text/messages.js'; import { isSaaS } from '../../../helpers/app/is-saas.js'; import { Constants } from '../../../helpers/constants/constants.js'; diff --git a/backend/src/entities/demo-data/demo-data.service.ts b/backend/src/entities/demo-data/demo-data.service.ts index 21c72f12..bb043d7b 100644 --- a/backend/src/entities/demo-data/demo-data.service.ts +++ b/backend/src/entities/demo-data/demo-data.service.ts @@ -1,7 +1,8 @@ import { Inject, Injectable } from '@nestjs/common'; -import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/enums/connection-types-enum.js'; +import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/shared/enums/connection-types-enum.js'; import { IGlobalDatabaseContext } from '../../common/application/global-database-context.interface.js'; import { BaseType } from '../../common/data-injection.tokens.js'; +import { FilterCriteriaEnum } from '../../enums/filter-criteria.enum.js'; import { QueryOrderingEnum } from '../../enums/query-ordering.enum.js'; import { TableActionEventEnum } from '../../enums/table-action-event-enum.js'; import { TableActionTypeEnum } from '../../enums/table-action-type.enum.js'; @@ -20,6 +21,8 @@ import { CreateTableActionEventDS, } from '../table-actions/table-action-rules-module/application/data-structures/create-action-rules.ds.js'; import { buildEmptyActionRule } from '../table-actions/table-action-rules-module/utils/build-empty-action-rule.util.js'; +import { CreateTableFilterDs } from '../table-filters/application/data-structures/create-table-filters.ds.js'; +import { buildNewTableFiltersEntity } from '../table-filters/utils/build-new-table-filters-entity.util.js'; import { CreateTableSettingsDs } from '../table-settings/application/data-structures/create-table-settings.ds.js'; import { TableSettingsEntity } from '../table-settings/table-settings.entity.js'; import { buildNewTableSettingsEntity } from '../table-settings/utils/build-new-table-settings-entity.js'; @@ -28,9 +31,6 @@ import { buildDefaultAdminGroups } from '../user/utils/build-default-admin-group import { buildDefaultAdminPermissions } from '../user/utils/build-default-admin-permissions.js'; import { CreateTableWidgetDs } from '../widget/application/data-sctructures/create-table-widgets.ds.js'; import { buildNewTableWidgetEntity } from '../widget/utils/build-new-table-widget-entity.js'; -import { CreateTableFilterDs } from '../table-filters/application/data-structures/create-table-filters.ds.js'; -import { FilterCriteriaEnum } from '../../enums/filter-criteria.enum.js'; -import { buildNewTableFiltersEntity } from '../table-filters/utils/build-new-table-filters-entity.util.js'; @Injectable() export class DemoDataService { diff --git a/backend/src/entities/shared-jobs/shared-jobs.service.ts b/backend/src/entities/shared-jobs/shared-jobs.service.ts index 7b07ec5c..547d7d5f 100644 --- a/backend/src/entities/shared-jobs/shared-jobs.service.ts +++ b/backend/src/entities/shared-jobs/shared-jobs.service.ts @@ -1,18 +1,18 @@ import { Inject, Injectable } from '@nestjs/common'; import { getDataAccessObject } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/create-data-access-object.js'; import { TableDS } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/data-structures/table.ds.js'; -import { IDataAccessObject } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/interfaces/data-access-object.interface.js'; +import { IDataAccessObjectAgent } from '@rocketadmin/shared-code/dist/src/shared/interfaces/data-access-object-agent.interface.js'; +import { IDataAccessObject } from '@rocketadmin/shared-code/dist/src/shared/interfaces/data-access-object.interface.js'; +import * as Sentry from '@sentry/node'; import PQueue from 'p-queue'; import { IGlobalDatabaseContext } from '../../common/application/global-database-context.interface.js'; import { BaseType } from '../../common/data-injection.tokens.js'; +import { WidgetTypeEnum } from '../../enums/widget-type.enum.js'; import { ValidationHelper } from '../../helpers/validators/validation-helper.js'; +import { ConnectionEntity } from '../connection/connection.entity.js'; import { buildEmptyTableSettings } from '../table-settings/utils/build-empty-table-settings.js'; import { buildNewTableSettingsEntity } from '../table-settings/utils/build-new-table-settings-entity.js'; -import { ConnectionEntity } from '../connection/connection.entity.js'; import { TableWidgetEntity } from '../widget/table-widget.entity.js'; -import { WidgetTypeEnum } from '../../enums/widget-type.enum.js'; -import { IDataAccessObjectAgent } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/interfaces/data-access-object-agent.interface.js'; -import * as Sentry from '@sentry/node'; @Injectable() export class SharedJobsService { constructor( diff --git a/backend/src/entities/table/use-cases/add-row-in-table.use.case.ts b/backend/src/entities/table/use-cases/add-row-in-table.use.case.ts index 37d9d30c..de0ac3ca 100644 --- a/backend/src/entities/table/use-cases/add-row-in-table.use.case.ts +++ b/backend/src/entities/table/use-cases/add-row-in-table.use.case.ts @@ -2,8 +2,8 @@ import { HttpException, HttpStatus, Inject, Injectable } from '@nestjs/common'; import { getDataAccessObject } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/create-data-access-object.js'; import { ForeignKeyWithAutocompleteColumnsDS } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/data-structures/foreign-key-with-autocomplete-columns.ds.js'; import { ForeignKeyDS } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/data-structures/foreign-key.ds.js'; -import { IDataAccessObjectAgent } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/interfaces/data-access-object-agent.interface.js'; -import { IDataAccessObject } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/interfaces/data-access-object.interface.js'; +import { IDataAccessObjectAgent } from '@rocketadmin/shared-code/dist/src/shared/interfaces/data-access-object-agent.interface.js'; +import { IDataAccessObject } from '@rocketadmin/shared-code/dist/src/shared/interfaces/data-access-object.interface.js'; 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'; @@ -14,6 +14,7 @@ import { WidgetTypeEnum, } from '../../../enums/index.js'; import { TableActionEventEnum } from '../../../enums/table-action-event-enum.js'; +import { NonAvailableInFreePlanException } from '../../../exceptions/custom-exceptions/non-available-in-free-plan-exception.js'; import { Messages } from '../../../exceptions/text/messages.js'; import { isConnectionTypeAgent, isObjectEmpty, toPrettyErrorsMsg } from '../../../helpers/index.js'; import { AmplitudeService } from '../../amplitude/amplitude.service.js'; @@ -22,6 +23,7 @@ import { TableActionActivationService } from '../../table-actions/table-actions- import { TableLogsService } from '../../table-logs/table-logs.service.js'; import { AddRowInTableDs } from '../application/data-structures/add-row-in-table.ds.js'; import { ForeignKeyDSInfo, ReferencedTableNamesAndColumnsDs, TableRowRODs } from '../table-datastructures.js'; +import { convertBinaryDataInRowUtil } from '../utils/convert-binary-data-in-row.util.js'; import { convertHexDataInRowUtil } from '../utils/convert-hex-data-in-row.util.js'; import { formFullTableStructure } from '../utils/form-full-table-structure.js'; import { hashPasswordsInRowUtil } from '../utils/hash-passwords-in-row.util.js'; @@ -29,8 +31,6 @@ import { processUuidsInRowUtil } from '../utils/process-uuids-in-row-util.js'; import { removePasswordsFromRowsUtil } from '../utils/remove-password-from-row.util.js'; import { validateTableRowUtil } from '../utils/validate-table-row.util.js'; import { IAddRowInTable } from './table-use-cases.interface.js'; -import { NonAvailableInFreePlanException } from '../../../exceptions/custom-exceptions/non-available-in-free-plan-exception.js'; -import { convertBinaryDataInRowUtil } from '../utils/convert-binary-data-in-row.util.js'; @Injectable() export class AddRowInTableUseCase extends AbstractUseCase implements IAddRowInTable { diff --git a/backend/src/entities/table/use-cases/get-row-by-primary-key.use.case.ts b/backend/src/entities/table/use-cases/get-row-by-primary-key.use.case.ts index e349e3ae..babb27ed 100644 --- a/backend/src/entities/table/use-cases/get-row-by-primary-key.use.case.ts +++ b/backend/src/entities/table/use-cases/get-row-by-primary-key.use.case.ts @@ -14,8 +14,6 @@ import { convertHexDataInPrimaryKeyUtil } from '../utils/convert-hex-data-in-pri import { formFullTableStructure } from '../utils/form-full-table-structure.js'; import { removePasswordsFromRowsUtil } from '../utils/remove-password-from-row.util.js'; import { IGetRowByPrimaryKey } from './table-use-cases.interface.js'; -import { IDataAccessObjectAgent } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/interfaces/data-access-object-agent.interface.js'; -import { IDataAccessObject } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/interfaces/data-access-object.interface.js'; import { ForeignKeyWithAutocompleteColumnsDS } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/data-structures/foreign-key-with-autocomplete-columns.ds.js'; import { ForeignKeyDS } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/data-structures/foreign-key.ds.js'; import { UnknownSQLException } from '../../../exceptions/custom-exceptions/unknown-sql-exception.js'; @@ -25,6 +23,8 @@ import JSON5 from 'json5'; import { buildActionEventDto } from '../../table-actions/table-action-rules-module/utils/build-found-action-event-dto.util.js'; import { NonAvailableInFreePlanException } from '../../../exceptions/custom-exceptions/non-available-in-free-plan-exception.js'; import { findAvailableFields } from '../utils/find-available-fields.utils.js'; +import { IDataAccessObjectAgent } from '@rocketadmin/shared-code/dist/src/shared/interfaces/data-access-object-agent.interface.js'; +import { IDataAccessObject } from '@rocketadmin/shared-code/dist/src/shared/interfaces/data-access-object.interface.js'; @Injectable() export class GetRowByPrimaryKeyUseCase diff --git a/backend/src/entities/table/use-cases/get-table-rows.use.case.ts b/backend/src/entities/table/use-cases/get-table-rows.use.case.ts index 07bcf667..549a4669 100644 --- a/backend/src/entities/table/use-cases/get-table-rows.use.case.ts +++ b/backend/src/entities/table/use-cases/get-table-rows.use.case.ts @@ -3,8 +3,6 @@ import { getDataAccessObject } from '@rocketadmin/shared-code/dist/src/data-acce import { ForeignKeyWithAutocompleteColumnsDS } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/data-structures/foreign-key-with-autocomplete-columns.ds.js'; import { ForeignKeyDS } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/data-structures/foreign-key.ds.js'; import { TableSettingsDS } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/data-structures/table-settings.ds.js'; -import { IDataAccessObjectAgent } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/interfaces/data-access-object-agent.interface.js'; -import { IDataAccessObject } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/interfaces/data-access-object.interface.js'; import { FoundRowsDS } from '@rocketadmin/shared-code/src/data-access-layer/shared/data-structures/found-rows.ds.js'; import Sentry from '@sentry/minimal'; import JSON5 from 'json5'; @@ -39,8 +37,10 @@ import { formFullTableStructure } from '../utils/form-full-table-structure.js'; import { isHexString } from '../utils/is-hex-string.js'; import { processRowsUtil } from '../utils/process-found-rows-util.js'; import { IGetTableRows } from './table-use-cases.interface.js'; -import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/enums/connection-types-enum.js'; import { findAvailableFields } from '../utils/find-available-fields.utils.js'; +import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/shared/enums/connection-types-enum.js'; +import { IDataAccessObjectAgent } from '@rocketadmin/shared-code/dist/src/shared/interfaces/data-access-object-agent.interface.js'; +import { IDataAccessObject } from '@rocketadmin/shared-code/dist/src/shared/interfaces/data-access-object.interface.js'; @Injectable() export class GetTableRowsUseCase extends AbstractUseCase implements IGetTableRows { diff --git a/backend/src/entities/table/use-cases/get-table-structure.use.case.ts b/backend/src/entities/table/use-cases/get-table-structure.use.case.ts index 784173c6..c870f8f2 100644 --- a/backend/src/entities/table/use-cases/get-table-structure.use.case.ts +++ b/backend/src/entities/table/use-cases/get-table-structure.use.case.ts @@ -1,9 +1,17 @@ import { HttpException, HttpStatus, Inject, Injectable } from '@nestjs/common'; +import { getDataAccessObject } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/create-data-access-object.js'; +import { ForeignKeyWithAutocompleteColumnsDS } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/data-structures/foreign-key-with-autocomplete-columns.ds.js'; +import { ForeignKeyDS } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/data-structures/foreign-key.ds.js'; +import { IDataAccessObjectAgent } from '@rocketadmin/shared-code/dist/src/shared/interfaces/data-access-object-agent.interface.js'; +import { IDataAccessObject } from '@rocketadmin/shared-code/dist/src/shared/interfaces/data-access-object.interface.js'; +import JSON5 from 'json5'; 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 { getDataAccessObject } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/create-data-access-object.js'; import { WidgetTypeEnum } from '../../../enums/index.js'; +import { ExceptionOperations } from '../../../exceptions/custom-exceptions/exception-operation.js'; +import { NonAvailableInFreePlanException } from '../../../exceptions/custom-exceptions/non-available-in-free-plan-exception.js'; +import { UnknownSQLException } from '../../../exceptions/custom-exceptions/unknown-sql-exception.js'; import { Messages } from '../../../exceptions/text/messages.js'; import { isConnectionTypeAgent } from '../../../helpers/index.js'; import { buildFoundTableWidgetDs } from '../../widget/utils/build-found-table-widget-ds.js'; @@ -11,14 +19,6 @@ import { GetTableStructureDs } from '../application/data-structures/get-table-st import { ForeignKeyDSInfo, TableStructureDs } from '../table-datastructures.js'; import { formFullTableStructure } from '../utils/form-full-table-structure.js'; import { IGetTableStructure } from './table-use-cases.interface.js'; -import { IDataAccessObject } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/interfaces/data-access-object.interface.js'; -import { IDataAccessObjectAgent } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/interfaces/data-access-object-agent.interface.js'; -import { ForeignKeyWithAutocompleteColumnsDS } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/data-structures/foreign-key-with-autocomplete-columns.ds.js'; -import { ForeignKeyDS } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/data-structures/foreign-key.ds.js'; -import { UnknownSQLException } from '../../../exceptions/custom-exceptions/unknown-sql-exception.js'; -import { ExceptionOperations } from '../../../exceptions/custom-exceptions/exception-operation.js'; -import JSON5 from 'json5'; -import { NonAvailableInFreePlanException } from '../../../exceptions/custom-exceptions/non-available-in-free-plan-exception.js'; @Injectable() export class GetTableStructureUseCase diff --git a/backend/src/entities/table/use-cases/update-row-in-table.use.case.ts b/backend/src/entities/table/use-cases/update-row-in-table.use.case.ts index e5a45e36..0ff228b9 100644 --- a/backend/src/entities/table/use-cases/update-row-in-table.use.case.ts +++ b/backend/src/entities/table/use-cases/update-row-in-table.use.case.ts @@ -4,8 +4,8 @@ import { getDataAccessObject } from '@rocketadmin/shared-code/dist/src/data-acce import { ForeignKeyWithAutocompleteColumnsDS } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/data-structures/foreign-key-with-autocomplete-columns.ds.js'; import { ForeignKeyDS } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/data-structures/foreign-key.ds.js'; import { ReferencedTableNamesAndColumnsDS } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/data-structures/referenced-table-names-columns.ds.js'; -import { IDataAccessObjectAgent } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/interfaces/data-access-object-agent.interface.js'; -import { IDataAccessObject } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/interfaces/data-access-object.interface.js'; +import { IDataAccessObjectAgent } from '@rocketadmin/shared-code/dist/src/shared/interfaces/data-access-object-agent.interface.js'; +import { IDataAccessObject } from '@rocketadmin/shared-code/dist/src/shared/interfaces/data-access-object.interface.js'; import JSON5 from 'json5'; import AbstractUseCase from '../../../common/abstract-use.case.js'; import { IGlobalDatabaseContext } from '../../../common/application/global-database-context.interface.js'; @@ -18,6 +18,7 @@ import { } from '../../../enums/index.js'; import { TableActionEventEnum } from '../../../enums/table-action-event-enum.js'; import { ExceptionOperations } from '../../../exceptions/custom-exceptions/exception-operation.js'; +import { NonAvailableInFreePlanException } from '../../../exceptions/custom-exceptions/non-available-in-free-plan-exception.js'; import { UnknownSQLException } from '../../../exceptions/custom-exceptions/unknown-sql-exception.js'; import { Messages } from '../../../exceptions/text/messages.js'; import { @@ -38,7 +39,6 @@ import { hashPasswordsInRowUtil } from '../utils/hash-passwords-in-row.util.js'; import { processUuidsInRowUtil } from '../utils/process-uuids-in-row-util.js'; import { removePasswordsFromRowsUtil } from '../utils/remove-password-from-row.util.js'; import { IUpdateRowInTable } from './table-use-cases.interface.js'; -import { NonAvailableInFreePlanException } from '../../../exceptions/custom-exceptions/non-available-in-free-plan-exception.js'; @Injectable() export class UpdateRowInTableUseCase diff --git a/backend/src/exceptions/text/messages.ts b/backend/src/exceptions/text/messages.ts index 64971af8..0e75a4c7 100644 --- a/backend/src/exceptions/text/messages.ts +++ b/backend/src/exceptions/text/messages.ts @@ -1,3 +1,5 @@ +import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/shared/enums/connection-types-enum.js'; +import { UserRoleEnum } from '../../entities/user/enums/user-role.enum.js'; import { EncryptionAlgorithmEnum, LogOperationTypeEnum, @@ -6,11 +8,8 @@ import { UserActionEnum, WidgetTypeEnum, } from '../../enums/index.js'; - -import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/enums/connection-types-enum.js'; import { TableActionEventEnum } from '../../enums/table-action-event-enum.js'; import { TableActionMethodEnum } from '../../enums/table-action-method-enum.js'; -import { UserRoleEnum } from '../../entities/user/enums/user-role.enum.js'; import { enumToString } from '../../helpers/enum-to-string.js'; import { toPrettyErrorsMsg } from '../../helpers/index.js'; export const Messages = { diff --git a/backend/src/helpers/constants/constants.ts b/backend/src/helpers/constants/constants.ts index 8e2ed02b..195c7fdc 100644 --- a/backend/src/helpers/constants/constants.ts +++ b/backend/src/helpers/constants/constants.ts @@ -1,4 +1,3 @@ -import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/enums/connection-types-enum.js'; import { CreateConnectionDto } from '../../entities/connection/application/dto/create-connection.dto.js'; import { Knex } from 'knex'; import { getProcessVariable } from '../get-process-variable.js'; @@ -12,6 +11,7 @@ import { parseTestDynamoDBConnectionString, } from '../parsers/string-connection-to-database-parsers.js'; import { isTest } from '../app/is-test.js'; +import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/shared/enums/connection-types-enum.js'; export type TestConnectionsFromJSON = { //string value represents the connection string, to connect to the database @@ -27,7 +27,17 @@ export const Constants = { ROCKETADMIN_AUTHENTICATED_COOKIE: 'rocketadmin_authenticated', JWT_COOKIE_KEY_NAME: 'rocketadmin_cookie', FORBIDDEN_HOSTS: ['10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16', '127.0.0.0/8', 'fd00::/8'], - BINARY_DATATYPES: ['binary', 'bytea', 'varbinary', 'varbinary(max)', 'tinyblob', 'blob', 'mediumblob', 'longblob', 'raw'], + BINARY_DATATYPES: [ + 'binary', + 'bytea', + 'varbinary', + 'varbinary(max)', + 'tinyblob', + 'blob', + 'mediumblob', + 'longblob', + 'raw', + ], DEFAULT_LOG_ROWS_LIMIT: 500, MIDNIGHT_CRON_KEY: 1, MORNING_CRON_KEY: 2, diff --git a/backend/src/helpers/is-connection-entity-agent.ts b/backend/src/helpers/is-connection-entity-agent.ts index ffc45e9f..4b19199f 100644 --- a/backend/src/helpers/is-connection-entity-agent.ts +++ b/backend/src/helpers/is-connection-entity-agent.ts @@ -1,7 +1,9 @@ -import { ConnectionEntity } from '../entities/connection/connection.entity.js'; -import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/enums/connection-types-enum.js'; -import { ConnectionTypeTestEnum } from '../enums/connection-type.enum.js'; +import { + ConnectionTypesEnum, + ConnectionTypeTestEnum, +} from '@rocketadmin/shared-code/dist/src/shared/enums/connection-types-enum.js'; import { CreateConnectionDto } from '../entities/connection/application/dto/create-connection.dto.js'; +import { ConnectionEntity } from '../entities/connection/connection.entity.js'; export function isConnectionEntityAgent(connection: ConnectionEntity | CreateConnectionDto): boolean { const agentTypes = [ diff --git a/backend/src/helpers/parsers/string-connection-to-database-parsers.ts b/backend/src/helpers/parsers/string-connection-to-database-parsers.ts index 8e5bf8d8..1f767b26 100644 --- a/backend/src/helpers/parsers/string-connection-to-database-parsers.ts +++ b/backend/src/helpers/parsers/string-connection-to-database-parsers.ts @@ -1,4 +1,4 @@ -import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/enums/connection-types-enum.js'; +import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/shared/enums/connection-types-enum.js'; import { CreateConnectionDto } from '../../entities/connection/application/dto/create-connection.dto.js'; // postgresql://user:password@localhost:5432/mydatabase?ssh=true&privateSSHKey=key&sshHost=sshHost&sshPort=22&sshUsername=sshUser&ssl=true&cert=cert diff --git a/backend/test/ava-tests/saas-tests/action-rules-e2e.test.ts b/backend/test/ava-tests/saas-tests/action-rules-e2e.test.ts index 73b99b50..852f49a6 100644 --- a/backend/test/ava-tests/saas-tests/action-rules-e2e.test.ts +++ b/backend/test/ava-tests/saas-tests/action-rules-e2e.test.ts @@ -28,9 +28,9 @@ import { UpdateTableActionRuleBodyDTO } from '../../../src/entities/table-action import { ActivatedTableActionsDTO } from '../../../src/entities/table-actions/table-action-rules-module/application/dto/activated-table-actions.dto.js'; import nock from 'nock'; import { CreateConnectionDto } from '../../../src/entities/connection/application/dto/create-connection.dto.js'; -import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/enums/connection-types-enum.js'; import { FoundTableActionRulesRoDTO } from '../../../src/entities/table-actions/table-action-rules-module/application/dto/found-table-action-rules.ro.dto.js'; import { WinstonLogger } from '../../../src/entities/logging/winston-logger.js'; +import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/shared/enums/connection-types-enum.js'; const mockFactory = new MockFactory(); let app: INestApplication; diff --git a/backend/test/ava-tests/saas-tests/connection-e2e.test.ts b/backend/test/ava-tests/saas-tests/connection-e2e.test.ts index 0e8afe3c..b7f60cb4 100644 --- a/backend/test/ava-tests/saas-tests/connection-e2e.test.ts +++ b/backend/test/ava-tests/saas-tests/connection-e2e.test.ts @@ -2,7 +2,6 @@ import { faker } from '@faker-js/faker'; import { INestApplication, ValidationPipe } from '@nestjs/common'; import { Test } from '@nestjs/testing'; -import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/enums/connection-types-enum.js'; import test from 'ava'; import { ValidationError } from 'class-validator'; import cookieParser from 'cookie-parser'; @@ -22,6 +21,7 @@ import { } from '../../utils/register-user-and-return-user-info.js'; import { TestUtils } from '../../utils/test.utils.js'; import { WinstonLogger } from '../../../src/entities/logging/winston-logger.js'; +import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/shared/enums/connection-types-enum.js'; const mockFactory = new MockFactory(); let app: INestApplication; diff --git a/backend/test/mock.factory.ts b/backend/test/mock.factory.ts index 3a15b798..8afaa68b 100644 --- a/backend/test/mock.factory.ts +++ b/backend/test/mock.factory.ts @@ -1,16 +1,15 @@ import { faker } from '@faker-js/faker'; +import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/shared/enums/connection-types-enum.js'; +import json5 from 'json5'; import jwt from 'jsonwebtoken'; import { IRequestWithCognitoInfo } from '../src/authorization/index.js'; import { CreateConnectionPropertiesDto } from '../src/entities/connection-properties/dto/index.js'; +import { CreateConnectionDto } from '../src/entities/connection/application/dto/create-connection.dto.js'; +import { CreateTableActionDTO } from '../src/entities/table-actions/table-actions-module/dto/create-table-action.dto.js'; import { TableActionEntity } from '../src/entities/table-actions/table-actions-module/table-action.entity.js'; import { CreateTableWidgetDto } from '../src/entities/widget/dto/index.js'; import { AccessLevelEnum, PermissionTypeEnum, QueryOrderingEnum, WidgetTypeEnum } from '../src/enums/index.js'; import { TestConstants } from './mocks/test-constants.js'; -import json5 from 'json5'; -import { ConnectionTypeTestEnum } from '../src/enums/connection-type.enum.js'; -import { CreateConnectionDto } from '../src/entities/connection/application/dto/create-connection.dto.js'; -import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/enums/connection-types-enum.js'; -import { CreateTableActionDTO } from '../src/entities/table-actions/table-actions-module/dto/create-table-action.dto.js'; class CreateGroupDto { title: string; diff --git a/backend/test/utils/create-test-table.ts b/backend/test/utils/create-test-table.ts index 0c2e65f5..ccac973c 100644 --- a/backend/test/utils/create-test-table.ts +++ b/backend/test/utils/create-test-table.ts @@ -2,7 +2,6 @@ import { fa, faker, th } from '@faker-js/faker'; import { getRandomConstraintName, getRandomTestTableName } from './get-random-test-table-name.js'; import { getTestKnex } from './get-test-knex.js'; -import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/enums/connection-types-enum.js'; import ibmdb, { Database } from 'ibm_db'; import { MongoClient, Db, ObjectId } from 'mongodb'; import { DynamoDB, PutItemCommand, PutItemCommandInput } from '@aws-sdk/client-dynamodb'; @@ -12,6 +11,7 @@ import * as cassandra from 'cassandra-driver'; import { v4 as uuidv4 } from 'uuid'; import { createClient } from 'redis'; import { createClient as createClickHouseClient } from '@clickhouse/client'; +import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/shared/enums/connection-types-enum.js'; export async function createTestTable( connectionParams: any, diff --git a/backend/test/utils/get-test-knex.ts b/backend/test/utils/get-test-knex.ts index cb84b72e..f1079719 100644 --- a/backend/test/utils/get-test-knex.ts +++ b/backend/test/utils/get-test-knex.ts @@ -1,8 +1,8 @@ import knex from 'knex'; import { Knex } from 'knex'; import { LRUCache } from 'lru-cache'; -import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/enums/connection-types-enum.js'; import { Constants } from '../../src/helpers/constants/constants.js'; +import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/shared/enums/connection-types-enum.js'; const knexCache = new LRUCache(Constants.DEFAULT_CONNECTION_CACHE_OPTIONS); diff --git a/rocketadmin-agent/src/dal/shared/create-dao.ts b/rocketadmin-agent/src/dal/shared/create-dao.ts index b8382f23..fc08e1b4 100644 --- a/rocketadmin-agent/src/dal/shared/create-dao.ts +++ b/rocketadmin-agent/src/dal/shared/create-dao.ts @@ -1,6 +1,6 @@ +import { IDataAccessObject } from '@rocketadmin/shared-code/src/shared/interfaces/data-access-object.interface.js'; import { ICLIConnectionCredentials } from '../../interfaces/interfaces.js'; import { getDataAccessObject } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/create-data-access-object.js'; -import { IDataAccessObject } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/interfaces/data-access-object.interface.js'; export function createDao(connection: ICLIConnectionCredentials): IDataAccessObject { return getDataAccessObject(connection) as unknown as IDataAccessObject; diff --git a/rocketadmin-agent/src/helpers/cli/cli-questions.ts b/rocketadmin-agent/src/helpers/cli/cli-questions.ts index 41dacf4e..4abcb761 100644 --- a/rocketadmin-agent/src/helpers/cli/cli-questions.ts +++ b/rocketadmin-agent/src/helpers/cli/cli-questions.ts @@ -1,7 +1,7 @@ +import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/shared/enums/connection-types-enum.js'; import readlineSync from 'readline-sync'; import { Messages } from '../../text/messages.js'; import { Constants } from '../constants/constants.js'; -import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/enums/connection-types-enum.js'; export class CLIQuestionUtility { public static askConnectionToken(): string { diff --git a/rocketadmin-agent/src/helpers/validate-connection-data.ts b/rocketadmin-agent/src/helpers/validate-connection-data.ts index 56d2f056..50773d49 100644 --- a/rocketadmin-agent/src/helpers/validate-connection-data.ts +++ b/rocketadmin-agent/src/helpers/validate-connection-data.ts @@ -1,6 +1,6 @@ -import { Messages } from '../text/messages.js'; +import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/shared/enums/connection-types-enum.js'; import { ICLIConnectionCredentials } from '../interfaces/interfaces.js'; -import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/enums/connection-types-enum.js'; +import { Messages } from '../text/messages.js'; export function validateConnectionData(connectionData: ICLIConnectionCredentials): Array { const errors = []; diff --git a/rocketadmin-agent/src/main.ts b/rocketadmin-agent/src/main.ts index 06c4742f..7370ed6a 100644 --- a/rocketadmin-agent/src/main.ts +++ b/rocketadmin-agent/src/main.ts @@ -1,17 +1,17 @@ -import WebSocket from 'ws'; import { NestFactory } from '@nestjs/core'; +import WebSocket from 'ws'; import { AppModule } from './app.module.js'; import { CommandExecutor } from './command/command-executor.js'; -import { getConnectionToDbParams } from './helpers/get-connection-to-db-params.js'; import { OperationTypeEnum } from './enums/operation-type.enum.js'; -import { Messages } from './text/messages.js'; import { checkConnection } from './helpers/check-connection.js'; -import { ICLIConnectionCredentials } from './interfaces/interfaces.js'; -import { Config } from './shared/config/config.js'; import { CLIQuestionUtility } from './helpers/cli/cli-questions.js'; -import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/enums/connection-types-enum.js'; -import { mkDirIfNotExistsUtil } from './helpers/write-file-util.js'; import { Constants } from './helpers/constants/constants.js'; +import { getConnectionToDbParams } from './helpers/get-connection-to-db-params.js'; +import { mkDirIfNotExistsUtil } from './helpers/write-file-util.js'; +import { ICLIConnectionCredentials } from './interfaces/interfaces.js'; +import { Config } from './shared/config/config.js'; +import { Messages } from './text/messages.js'; +import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/shared/enums/connection-types-enum.js'; async function bootstrap() { const connectionCredentials: ICLIConnectionCredentials = Config.getConnectionConfig(); diff --git a/rocketadmin-agent/src/text/messages.ts b/rocketadmin-agent/src/text/messages.ts index bd0b8168..fb37df87 100644 --- a/rocketadmin-agent/src/text/messages.ts +++ b/rocketadmin-agent/src/text/messages.ts @@ -1,7 +1,7 @@ import { enumToString } from '../helpers/enum-to-string.js'; -import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/enums/connection-types-enum.js'; import { QueryOrderingEnum } from '../enums/query-ordering.enum.js'; import { Constants } from '../helpers/constants/constants.js'; +import { ConnectionTypesEnum } from '@rocketadmin/shared-code/dist/src/shared/enums/connection-types-enum.js'; export const Messages = { APPLICATION_ENCRYPTION_PASSWORD_INVALID: `Invalid encryption password`, diff --git a/rocketadmin-agent/test/app.e2e-spec.ts b/rocketadmin-agent/test/app.e2e-spec.ts deleted file mode 100644 index d6c79da2..00000000 --- a/rocketadmin-agent/test/app.e2e-spec.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { INestApplication } from '@nestjs/common'; -import request from 'supertest'; -import { AppModule } from './../src/app.module.js'; - -describe('AppController (e2e)', () => { - let app: INestApplication; - - beforeEach(async () => { - const moduleFixture: TestingModule = await Test.createTestingModule({ - imports: [AppModule], - }).compile(); - - app = moduleFixture.createNestApplication() as any; - await app.init(); - }); - - it('/ (GET)', () => { - return request(app.getHttpServer()).get('/').expect(200).expect('Hello World!'); - }); -}); diff --git a/rocketadmin-agent/test/command/command-executor-mssql.spec.ts b/rocketadmin-agent/test/command/command-executor-mssql.spec.ts deleted file mode 100644 index 935a9ed0..00000000 --- a/rocketadmin-agent/test/command/command-executor-mssql.spec.ts +++ /dev/null @@ -1,714 +0,0 @@ -import { faker } from '@faker-js/faker'; -import { AppModule } from '../../src/app.module.js'; -import { INestApplication } from '@nestjs/common'; -import { Knex, knex } from 'knex'; -import { Test } from '@nestjs/testing'; -import { ICLIConnectionCredentials } from '../../src/interfaces/interfaces.js'; -import { CommandExecutor } from '../../src/command/command-executor.js'; -import { OperationTypeEnum } from '../../src/enums/operation-type.enum.js'; -import { Constants } from '../../src/helpers/constants/constants.js'; -import { QueryOrderingEnum } from '../../src/enums/query-ordering.enum.js'; - -describe('Command executor tests', () => { - let app: INestApplication; - const testTableName = 'users'; - const testTableColumnName = 'name'; - const testTAbleSecondColumnName = 'email'; - const testSearchedUserName = 'Vasia'; - const testEntitiesSeedsCount = 42; - const connectionConfig: ICLIConnectionCredentials = { - cert: '', - database: 'TempDB', - host: 'localhost', - password: 'yNuXf@6T#BgoQ%U6knMp', - port: 5434, - schema: '', - sid: '', - ssl: false, - type: 'mssql', - username: 'sa', - azure_encryption: false, - token: 'token', - app_port: 3000, - application_save_option: false, - config_encryption_option: false, - encryption_password: undefined, - saving_logs_option: false, - }; - - async function resetMsSqlTestDB() { - const Knex = knex({ - client: connectionConfig.type, - connection: { - host: connectionConfig.host, - user: connectionConfig.username, - password: connectionConfig.password, - database: connectionConfig.database, - port: connectionConfig.port, - }, - }); - await Knex.schema.dropTableIfExists(testTableName); - await Knex.schema.createTableIfNotExists(testTableName, function (table) { - table.increments(); - table.string(testTableColumnName); - table.string(testTAbleSecondColumnName); - table.timestamps(); - }); - - for (let i = 0; i < testEntitiesSeedsCount; i++) { - if (i === 0 || i === testEntitiesSeedsCount - 21 || i === testEntitiesSeedsCount - 5) { - await Knex(testTableName).insert({ - [testTableColumnName]: testSearchedUserName, - [testTAbleSecondColumnName]: faker.internet.email(), - created_at: new Date(), - updated_at: new Date(), - }); - } else { - await Knex(testTableName).insert({ - [testTableColumnName]: faker.person.firstName(), - [testTAbleSecondColumnName]: faker.internet.email(), - created_at: new Date(), - updated_at: new Date(), - }); - } - } - await Knex.destroy(); - } - - beforeEach(async () => { - jest.setTimeout(10000); - const moduleFixture = await Test.createTestingModule({ - imports: [AppModule], - }).compile(); - - app = moduleFixture.createNestApplication() as any; - await app.init(); - await resetMsSqlTestDB(); - }); - - describe('execute command', () => { - describe('addRowInTable command', () => { - it('should return added row primary key when call add row in table', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const fakeName = faker.person.firstName(); - const fakeMail = faker.internet.email(); - - const row = { - [testTableColumnName]: fakeName, - [testTAbleSecondColumnName]: fakeMail, - }; - - const commandData = { - operationType: OperationTypeEnum.addRowInTable, - tableName: testTableName, - row: row, - primaryKey: undefined, - tableSettings: undefined, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result.id).toBe(43); - }); - - it('should return an error when call add row in table without passed row', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.addRowInTable, - tableName: testTableName, - row: undefined, - primaryKey: undefined, - tableSettings: undefined, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result instanceof Error).toBeTruthy(); - }); - }); - - describe('deleteRowInTable command', () => { - it('should return 1 when call delete row in table', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.deleteRowInTable, - tableName: testTableName, - row: undefined, - primaryKey: { id: 1 }, - tableSettings: undefined, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - - expect(result).toStrictEqual([1]); - }); - - it('should return an error when call delete row in table without primary key', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.deleteRowInTable, - tableName: testTableName, - row: undefined, - primaryKey: undefined, - tableSettings: undefined, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result instanceof Error).toBeTruthy(); - }); - }); - - describe('getRowByPrimaryKey command', () => { - it('should return row by primary key when call get row by primary key', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getRowByPrimaryKey, - tableName: testTableName, - row: undefined, - primaryKey: { id: 1 }, - tableSettings: undefined, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result.length).toBe(1); - expect(result[0].id).toBe(1); - expect(result[0].hasOwnProperty('name')).toBeTruthy(); - expect(result[0].hasOwnProperty('email')).toBeTruthy(); - expect(result[0].hasOwnProperty('created_at')).toBeTruthy(); - expect(result[0].hasOwnProperty('updated_at')).toBeTruthy(); - }); - - it('should return an error when called get row by primary key without primary key', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getRowByPrimaryKey, - tableName: testTableName, - row: undefined, - primaryKey: undefined, - tableSettings: undefined, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result instanceof Error).toBeTruthy(); - }); - }); - - describe('getRowsFromTable command', () => { - it('should return all rows when call get rows ', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getRowsFromTable, - tableName: testTableName, - row: undefined, - primaryKey: undefined, - tableSettings: {} as any, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result.data.length).toBe(20); - expect(result.hasOwnProperty('pagination')); - expect(result.pagination.total).toBe(testEntitiesSeedsCount); - expect(result.pagination.perPage).toBe(Constants.DEFAULT_PAGINATION.perPage); - expect(result.pagination.currentPage).toBe(Constants.DEFAULT_PAGINATION.page); - expect(result.pagination.lastPage).toBe( - Math.ceil(testEntitiesSeedsCount / Constants.DEFAULT_PAGINATION.perPage), - ); - }); - - it('should return an error when call get rows without table name', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getRowsFromTable, - tableName: undefined, - row: undefined, - primaryKey: undefined, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result instanceof Error).toBeTruthy(); - }); - }); - - describe('getTableForeignKeys command', () => { - it('should return all empty foreign keys array when called get table foreign keys', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getTableForeignKeys, - tableName: testTableName, - row: undefined, - primaryKey: undefined, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result.length).toBe(0); - }); - - it('should return an error when called get table foreign keys without table name', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getTableForeignKeys, - tableName: undefined, - row: undefined, - primaryKey: undefined, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result instanceof Error).toBeTruthy(); - }); - }); - - describe('getTablePrimaryColumns command', () => { - it('should return primary keys array when called get table primary column operation', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getTablePrimaryColumns, - tableName: testTableName, - row: undefined, - primaryKey: undefined, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result.length).toBe(1); - expect(result[0].column_name).toBe('id'); - expect(result[0].data_type).toBe('int'); - }); - - it('should return an error when called get table primary column operation without table name', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getTablePrimaryColumns, - tableName: undefined, - row: undefined, - primaryKey: undefined, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result instanceof Error).toBeTruthy(); - }); - }); - - describe('getTableStructure command', () => { - it('should return table structure when called get table structure operation', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getTableStructure, - tableName: testTableName, - row: undefined, - primaryKey: undefined, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - - expect(result.length).toBe(5); - for (const element of result) { - expect(element.hasOwnProperty('column_name')).toBeTruthy(); - expect(element.hasOwnProperty('column_default')).toBeTruthy(); - expect(element.hasOwnProperty('data_type')).toBeTruthy(); - expect(element.hasOwnProperty('character_maximum_length')).toBeTruthy(); - expect(element.hasOwnProperty('allow_null')).toBeTruthy(); - } - }); - - it('should return an error when called get table structure operation without table name', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getTableStructure, - tableName: undefined, - row: undefined, - primaryKey: undefined, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result instanceof Error).toBeTruthy(); - }); - }); - - describe('getTablesFromDB command', () => { - it('should return tables when called get tables from db operation', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getTablesFromDB, - tableName: undefined, - row: undefined, - primaryKey: undefined, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result.length).toBe(1); - expect(result[0]).toBe(testTableName); - }); - - it('should return an exception when called get tables from db operation without operation type', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: undefined, - tableName: undefined, - row: undefined, - primaryKey: undefined, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result instanceof Error).toBeTruthy(); - }); - }); - - describe('updateRowInTable command', () => { - it('should return 1 when called update table row primary key operation', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const fakeName = faker.person.firstName(); - const fakeMail = faker.internet.email(); - - const row = { - [testTableColumnName]: fakeName, - [testTAbleSecondColumnName]: fakeMail, - }; - - const primaryKey = { - id: 1, - }; - - const commandData = { - operationType: OperationTypeEnum.updateRowInTable, - tableName: testTableName, - row: row, - primaryKey: primaryKey, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result).toStrictEqual([1]); - }); - - it('should return when called update row primary operation without row', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const primaryKey = { - id: 1, - }; - - const commandData = { - operationType: OperationTypeEnum.updateRowInTable, - tableName: testTableName, - row: undefined, - primaryKey: primaryKey, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result instanceof Error).toBeTruthy(); - }); - }); - - describe('validateSettings command', () => { - it('should return empty errors array when called validate settings operation', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const settings = { - connection_id: faker.string.uuid(), - table_name: testTableName, - display_name: '', - search_fields: [testTableColumnName], - excluded_fields: undefined, - list_fields: undefined, - identification_fields: undefined, - list_per_page: undefined, - ordering: QueryOrderingEnum.ASC, - ordering_field: undefined, - readonly_fields: undefined, - sortable_by: undefined, - autocomplete_columns: undefined, - custom_fields: undefined, - table_widgets: undefined, - }; - - const commandData = { - operationType: OperationTypeEnum.validateSettings, - tableName: testTableName, - row: undefined, - primaryKey: undefined, - tableSettings: settings, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result.length).toBe(0); - }); - - it('should return an error array with error when called validate settings operation with wrong search field', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const settings = { - connection_id: faker.string.uuid(), - table_name: testTableName, - display_name: '', - search_fields: [faker.lorem.words(1)], - excluded_fields: undefined, - list_fields: undefined, - identification_fields: undefined, - list_per_page: undefined, - ordering: QueryOrderingEnum.ASC, - ordering_field: undefined, - readonly_fields: undefined, - sortable_by: undefined, - autocomplete_columns: undefined, - custom_fields: undefined, - table_widgets: undefined, - }; - - const commandData = { - operationType: OperationTypeEnum.validateSettings, - tableName: testTableName, - row: undefined, - primaryKey: undefined, - tableSettings: settings, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result.length).toBe(1); - }); - }); - }); -}); diff --git a/rocketadmin-agent/test/command/command-executor-mysql.spec.ts b/rocketadmin-agent/test/command/command-executor-mysql.spec.ts deleted file mode 100644 index ef51f862..00000000 --- a/rocketadmin-agent/test/command/command-executor-mysql.spec.ts +++ /dev/null @@ -1,715 +0,0 @@ -import { faker } from '@faker-js/faker'; -import { AppModule } from '../../src/app.module.js'; -import { INestApplication } from '@nestjs/common'; -import { Knex, knex } from 'knex'; -import { Test } from '@nestjs/testing'; -import { ICLIConnectionCredentials } from '../../src/interfaces/interfaces.js'; -import { CommandExecutor } from '../../src/command/command-executor.js'; -import { OperationTypeEnum } from '../../src/enums/operation-type.enum.js'; -import { Constants } from '../../src/helpers/constants/constants.js'; -import { QueryOrderingEnum } from '../../src/enums/query-ordering.enum.js'; - -describe('Command executor tests', () => { - let app: INestApplication; - const testTableName = 'users'; - const testTableColumnName = 'name'; - const testTAbleSecondColumnName = 'email'; - const testSearchedUserName = 'Vasia'; - const testEntitiesSeedsCount = 42; - const connectionConfig: ICLIConnectionCredentials = { - cert: '', - database: 'testDB', - host: 'localhost', - password: '123', - port: 3308, - schema: '', - sid: '', - ssl: false, - type: 'mysql', - username: 'root', - app_port: 3000, - token: 'token', - azure_encryption: false, - application_save_option: false, - config_encryption_option: false, - encryption_password: undefined, - saving_logs_option: false, - }; - - async function resetMySqlTestDB() { - const Knex = knex({ - client: 'mysql2', - connection: { - host: connectionConfig.host, - user: connectionConfig.username, - password: connectionConfig.password, - database: connectionConfig.database, - port: connectionConfig.port, - }, - }); - await Knex.schema.dropTableIfExists(testTableName); - await Knex.schema.createTableIfNotExists(testTableName, function (table) { - table.increments(); - table.string(testTableColumnName); - table.string(testTAbleSecondColumnName); - table.timestamps(); - }); - - for (let i = 0; i < testEntitiesSeedsCount; i++) { - if (i === 0 || i === testEntitiesSeedsCount - 21 || i === testEntitiesSeedsCount - 5) { - await Knex(testTableName).insert({ - [testTableColumnName]: testSearchedUserName, - [testTAbleSecondColumnName]: faker.internet.email(), - created_at: new Date(), - updated_at: new Date(), - }); - } else { - await Knex(testTableName).insert({ - [testTableColumnName]: faker.person.firstName(), - [testTAbleSecondColumnName]: faker.internet.email(), - created_at: new Date(), - updated_at: new Date(), - }); - } - } - await Knex.destroy(); - } - - beforeEach(async () => { - jest.setTimeout(10000); - const moduleFixture = await Test.createTestingModule({ - imports: [AppModule], - }).compile(); - - app = moduleFixture.createNestApplication() as any; - await app.init(); - await resetMySqlTestDB(); - }); - - describe('execute command', () => { - describe('addRowInTable command', () => { - it('should return added row primary key when call add row in table', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const fakeName = faker.person.firstName(); - const fakeMail = faker.internet.email(); - - const row = { - id: 999, - [testTableColumnName]: fakeName, - [testTAbleSecondColumnName]: fakeMail, - }; - - const commandData = { - operationType: OperationTypeEnum.addRowInTable, - tableName: testTableName, - row: row, - primaryKey: undefined, - tableSettings: undefined, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result.id).toBe(999); - }); - - it('should return an error when call add row in table without passed row', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.addRowInTable, - tableName: testTableName, - row: undefined, - primaryKey: undefined, - tableSettings: undefined, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result instanceof Error).toBeTruthy(); - }); - }); - - describe('deleteRowInTable command', () => { - it('should return 1 when call delete row in table', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.deleteRowInTable, - tableName: testTableName, - row: undefined, - primaryKey: { id: 1 }, - tableSettings: undefined, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - - expect(result).toBe(1); - }); - - it('should return an error when call delete row in table without primary key', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.deleteRowInTable, - tableName: testTableName, - row: undefined, - primaryKey: undefined, - tableSettings: undefined, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result instanceof Error).toBeTruthy(); - }); - }); - - describe('getRowByPrimaryKey command', () => { - it('should return row by primary key when call get row by primary key', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getRowByPrimaryKey, - tableName: testTableName, - row: undefined, - primaryKey: { id: 1 }, - tableSettings: undefined, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result.length).toBe(1); - expect(result[0].id).toBe(1); - expect(result[0].hasOwnProperty('name')).toBeTruthy(); - expect(result[0].hasOwnProperty('email')).toBeTruthy(); - expect(result[0].hasOwnProperty('created_at')).toBeTruthy(); - expect(result[0].hasOwnProperty('updated_at')).toBeTruthy(); - }); - - it('should return an error when called get row by primary key without primary key', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getRowByPrimaryKey, - tableName: testTableName, - row: undefined, - primaryKey: undefined, - tableSettings: undefined, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result instanceof Error).toBeTruthy(); - }); - }); - - describe('getRowsFromTable command', () => { - it('should return all rows when call get rows ', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getRowsFromTable, - tableName: testTableName, - row: undefined, - primaryKey: undefined, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result.data.length).toBe(20); - expect(result.hasOwnProperty('pagination')); - expect(result.pagination.total).toBe(testEntitiesSeedsCount); - expect(result.pagination.perPage).toBe(Constants.DEFAULT_PAGINATION.perPage); - expect(result.pagination.currentPage).toBe(Constants.DEFAULT_PAGINATION.page); - expect(result.pagination.lastPage).toBe( - Math.ceil(testEntitiesSeedsCount / Constants.DEFAULT_PAGINATION.perPage), - ); - }); - - it('should return an error when call get rows without table name', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getRowsFromTable, - tableName: undefined, - row: undefined, - primaryKey: undefined, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result instanceof Error).toBeTruthy(); - }); - }); - - describe('getTableForeignKeys command', () => { - it('should return all empty foreign keys array when called get table foreign keys', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getTableForeignKeys, - tableName: testTableName, - row: undefined, - primaryKey: undefined, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result.length).toBe(0); - }); - - it('should return an error when called get table foreign keys without table name', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getTableForeignKeys, - tableName: undefined, - row: undefined, - primaryKey: undefined, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result instanceof Error).toBeTruthy(); - }); - }); - - describe('getTablePrimaryColumns command', () => { - it('should return primary keys array when called get table primary column operation', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getTablePrimaryColumns, - tableName: testTableName, - row: undefined, - primaryKey: undefined, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result.length).toBe(1); - expect(result[0].column_name).toBe('id'); - expect(result[0].data_type).toBe('int'); - }); - - it('should return an error when called get table primary column operation without table name', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getTablePrimaryColumns, - tableName: undefined, - row: undefined, - primaryKey: undefined, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result instanceof Error).toBeTruthy(); - }); - }); - - describe('getTableStructure command', () => { - it('should return table structure when called get table structure operation', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getTableStructure, - tableName: testTableName, - row: undefined, - primaryKey: undefined, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - - expect(result.length).toBe(5); - for (const element of result) { - expect(element.hasOwnProperty('column_name')).toBeTruthy(); - expect(element.hasOwnProperty('column_default')).toBeTruthy(); - expect(element.hasOwnProperty('data_type')).toBeTruthy(); - expect(element.hasOwnProperty('character_maximum_length')).toBeTruthy(); - expect(element.hasOwnProperty('allow_null')).toBeTruthy(); - } - }); - - it('should return an error when called get table structure operation without table name', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getTableStructure, - tableName: undefined, - row: undefined, - primaryKey: undefined, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result instanceof Error).toBeTruthy(); - }); - }); - - describe('getTablesFromDB command', () => { - it('should return tables when called get tables from db operation', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getTablesFromDB, - tableName: undefined, - row: undefined, - primaryKey: undefined, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result.length).toBe(1); - expect(result[0]).toBe(testTableName); - }); - - it('should return an exception when called get tables from db operation without operation type', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: undefined, - tableName: undefined, - row: undefined, - primaryKey: undefined, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result instanceof Error).toBeTruthy(); - }); - }); - - describe('updateRowInTable command', () => { - it('should return 1 when called update table row primary key operation', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const fakeName = faker.person.firstName(); - const fakeMail = faker.internet.email(); - - const row = { - [testTableColumnName]: fakeName, - [testTAbleSecondColumnName]: fakeMail, - }; - - const primaryKey = { - id: 1, - }; - - const commandData = { - operationType: OperationTypeEnum.updateRowInTable, - tableName: testTableName, - row: row, - primaryKey: primaryKey, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result).toBe(1); - }); - - it('should return when called update row primary operation without row', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const primaryKey = { - id: 1, - }; - - const commandData = { - operationType: OperationTypeEnum.updateRowInTable, - tableName: testTableName, - row: undefined, - primaryKey: primaryKey, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result instanceof Error).toBeTruthy(); - }); - }); - - describe('validateSettings command', () => { - it('should return empty errors array when called validate settings operation', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const settings = { - connection_id: faker.string.uuid(), - table_name: testTableName, - display_name: '', - search_fields: [testTableColumnName], - excluded_fields: undefined, - list_fields: undefined, - identification_fields: undefined, - list_per_page: undefined, - ordering: QueryOrderingEnum.ASC, - ordering_field: undefined, - readonly_fields: undefined, - sortable_by: undefined, - autocomplete_columns: undefined, - custom_fields: undefined, - table_widgets: undefined, - }; - - const commandData = { - operationType: OperationTypeEnum.validateSettings, - tableName: testTableName, - row: undefined, - primaryKey: undefined, - tableSettings: settings, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result.length).toBe(0); - }); - - it('should return an error array with error when called validate settings operation with wrong search field', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const settings = { - connection_id: faker.string.uuid(), - table_name: testTableName, - display_name: '', - search_fields: [faker.lorem.words(1)], - excluded_fields: undefined, - list_fields: undefined, - identification_fields: undefined, - list_per_page: undefined, - ordering: QueryOrderingEnum.ASC, - ordering_field: undefined, - readonly_fields: undefined, - sortable_by: undefined, - autocomplete_columns: undefined, - custom_fields: undefined, - table_widgets: undefined, - }; - - const commandData = { - operationType: OperationTypeEnum.validateSettings, - tableName: testTableName, - row: undefined, - primaryKey: undefined, - tableSettings: settings, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result.length).toBe(1); - }); - }); - }); -}); diff --git a/rocketadmin-agent/test/command/command-executor-orecle.spec.ts b/rocketadmin-agent/test/command/command-executor-orecle.spec.ts deleted file mode 100644 index b20eaf4f..00000000 --- a/rocketadmin-agent/test/command/command-executor-orecle.spec.ts +++ /dev/null @@ -1,718 +0,0 @@ -import { faker } from '@faker-js/faker'; -import { AppModule } from '../../src/app.module.js'; -import { INestApplication } from '@nestjs/common'; -import { Knex, knex } from 'knex'; -import { Test } from '@nestjs/testing'; -import { ICLIConnectionCredentials } from '../../src/interfaces/interfaces.js'; -import { CommandExecutor } from '../../src/command/command-executor.js'; -import { OperationTypeEnum } from '../../src/enums/operation-type.enum.js'; -import { Constants } from '../../src/helpers/constants/constants.js'; -import { QueryOrderingEnum } from '../../src/enums/query-ordering.enum.js'; - -describe('Command executor tests', () => { - let app: INestApplication; - const testTableName = 'users'; - const testTableColumnName = 'name'; - const testTAbleSecondColumnName = 'email'; - const testSearchedUserName = 'Vasia'; - const testEntitiesSeedsCount = 42; - const connectionConfig: ICLIConnectionCredentials = { - cert: '', - database: 'ORCL', - host: 'localhost', - password: 'abc123', - port: 1521, - schema: null, - sid: 'XE', - ssl: false, - type: 'oracledb', - username: 'test', - token: 'token', - azure_encryption: false, - app_port: 3000, - application_save_option: false, - config_encryption_option: false, - encryption_password: undefined, - saving_logs_option: false, - }; - - async function resetOracleTestDB() { - const { host, username, password, database, port, type, ssl, cert, sid } = connectionConfig; - const Knex = knex({ - client: type, - connection: { - user: username, - database: database, - password: password, - connectString: `${host}:${port}/${sid ? sid : ''}`, - ssl: ssl ? { ca: cert } : { rejectUnauthorized: false }, - }, - }); - await Knex.schema.dropTableIfExists(testTableName.toUpperCase()); - await Knex.schema.dropTableIfExists(testTableName); - await Knex.schema.createTableIfNotExists(testTableName, function (table) { - table.increments(); - table.string(testTableColumnName); - table.string(testTAbleSecondColumnName); - table.timestamps(); - }); - - for (let i = 0; i < testEntitiesSeedsCount; i++) { - if (i === 0 || i === testEntitiesSeedsCount - 21 || i === testEntitiesSeedsCount - 5) { - await Knex(testTableName).insert({ - [testTableColumnName]: testSearchedUserName, - [testTAbleSecondColumnName]: faker.internet.email(), - created_at: new Date(), - updated_at: new Date(), - }); - } else { - await Knex(testTableName).insert({ - [testTableColumnName]: faker.person.firstName(), - [testTAbleSecondColumnName]: faker.internet.email(), - created_at: new Date(), - updated_at: new Date(), - }); - } - } - await Knex.destroy(); - } - - beforeEach(async () => { - jest.setTimeout(10000); - const moduleFixture = await Test.createTestingModule({ - imports: [AppModule], - }).compile(); - - app = moduleFixture.createNestApplication() as any; - await app.init(); - await resetOracleTestDB(); - }); - - describe('execute command', () => { - describe('addRowInTable command', () => { - it('should return added row primary key when call add row in table', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const fakeName = faker.person.firstName(); - const fakeMail = faker.internet.email(); - - const row = { - id: 999, - [testTableColumnName]: fakeName, - [testTAbleSecondColumnName]: fakeMail, - }; - - const commandData = { - operationType: OperationTypeEnum.addRowInTable, - tableName: testTableName, - row: row, - primaryKey: undefined, - tableSettings: undefined, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result.id).toBe(999); - }); - - it('should return an error when call add row in table without passed row', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.addRowInTable, - tableName: testTableName, - row: undefined, - primaryKey: undefined, - tableSettings: undefined, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result instanceof Error).toBeTruthy(); - }); - }); - - describe('deleteRowInTable command', () => { - it('should return 1 when call delete row in table', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.deleteRowInTable, - tableName: testTableName, - row: undefined, - primaryKey: { id: 1 }, - tableSettings: undefined, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - - expect(result).toBe(1); - }); - - it('should return an error when call delete row in table without primary key', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.deleteRowInTable, - tableName: testTableName, - row: undefined, - primaryKey: undefined, - tableSettings: undefined, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result instanceof Error).toBeTruthy(); - }); - }); - - describe('getRowByPrimaryKey command', () => { - it('should return row by primary key when call get row by primary key', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getRowByPrimaryKey, - tableName: testTableName, - row: undefined, - primaryKey: { id: 1 }, - tableSettings: undefined, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result.length).toBe(1); - expect(result[0].id).toBe(1); - expect(result[0].hasOwnProperty('name')).toBeTruthy(); - expect(result[0].hasOwnProperty('email')).toBeTruthy(); - expect(result[0].hasOwnProperty('created_at')).toBeTruthy(); - expect(result[0].hasOwnProperty('updated_at')).toBeTruthy(); - }); - - it('should return an error when called get row by primary key without primary key', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getRowByPrimaryKey, - tableName: testTableName, - row: undefined, - primaryKey: undefined, - tableSettings: undefined, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result instanceof Error).toBeTruthy(); - }); - }); - - describe('getRowsFromTable command', () => { - it('should return all rows when call get rows ', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getRowsFromTable, - tableName: testTableName, - row: undefined, - primaryKey: undefined, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - - expect(result.data.length).toBe(20); - expect(result.hasOwnProperty('pagination')); - expect(result.pagination.total).toBe(testEntitiesSeedsCount); - expect(result.pagination.perPage).toBe(Constants.DEFAULT_PAGINATION.perPage); - expect(result.pagination.currentPage).toBe(Constants.DEFAULT_PAGINATION.page); - expect(result.pagination.lastPage).toBe( - Math.ceil(testEntitiesSeedsCount / Constants.DEFAULT_PAGINATION.perPage), - ); - }); - - it('should return an error when call get rows without table name', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getRowsFromTable, - tableName: undefined, - row: undefined, - primaryKey: undefined, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result instanceof Error).toBeTruthy(); - }); - }); - - describe('getTableForeignKeys command', () => { - it('should return all empty foreign keys array when called get table foreign keys', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getTableForeignKeys, - tableName: testTableName, - row: undefined, - primaryKey: undefined, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result.length).toBe(0); - }); - - it('should return an error when called get table foreign keys without table name', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getTableForeignKeys, - tableName: undefined, - row: undefined, - primaryKey: undefined, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result instanceof Error).toBeTruthy(); - }); - }); - - describe('getTablePrimaryColumns command', () => { - it('should return primary keys array when called get table primary column operation', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getTablePrimaryColumns, - tableName: testTableName, - row: undefined, - primaryKey: undefined, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result.length).toBe(1); - expect(result[0].column_name).toBe('id'); - }); - - it('should return an error when called get table primary column operation without table name', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getTablePrimaryColumns, - tableName: undefined, - row: undefined, - primaryKey: undefined, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result instanceof Error).toBeTruthy(); - }); - }); - - describe('getTableStructure command', () => { - it('should return table structure when called get table structure operation', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getTableStructure, - tableName: testTableName, - row: undefined, - primaryKey: undefined, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - - expect(result.length).toBe(5); - for (const element of result) { - expect(element.hasOwnProperty('column_name')).toBeTruthy(); - expect(element.hasOwnProperty('column_default')).toBeTruthy(); - expect(element.hasOwnProperty('data_type')).toBeTruthy(); - expect(element.hasOwnProperty('character_maximum_length')).toBeTruthy(); - expect(element.hasOwnProperty('allow_null')).toBeTruthy(); - } - }); - - //todo - xit('should return an error when called get table structure operation without table name', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getTableStructure, - tableName: undefined, - row: undefined, - primaryKey: undefined, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result instanceof Error).toBeTruthy(); - }); - }); - - describe('getTablesFromDB command', () => { - it('should return tables when called get tables from db operation', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getTablesFromDB, - tableName: undefined, - row: undefined, - primaryKey: undefined, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result.length).toBe(1); - expect(result[0]).toBe(testTableName); - }); - - it('should return an exception when called get tables from db operation without operation type', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: undefined, - tableName: undefined, - row: undefined, - primaryKey: undefined, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result instanceof Error).toBeTruthy(); - }); - }); - - describe('updateRowInTable command', () => { - it('should return 1 when called update table row primary key operation', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const fakeName = faker.person.firstName(); - const fakeMail = faker.internet.email(); - - const row = { - [testTableColumnName]: fakeName, - [testTAbleSecondColumnName]: fakeMail, - }; - - const primaryKey = { - id: 1, - }; - - const commandData = { - operationType: OperationTypeEnum.updateRowInTable, - tableName: testTableName, - row: row, - primaryKey: primaryKey, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result).toStrictEqual([]); - }); - - it('should return when called update row primary operation without row', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const primaryKey = { - id: 1, - }; - - const commandData = { - operationType: OperationTypeEnum.updateRowInTable, - tableName: testTableName, - row: undefined, - primaryKey: primaryKey, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result instanceof Error).toBeTruthy(); - }); - }); - - describe('validateSettings command', () => { - it('should return empty errors array when called validate settings operation', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const settings = { - connection_id: faker.string.uuid(), - table_name: testTableName, - display_name: '', - search_fields: [testTableColumnName], - excluded_fields: undefined, - list_fields: undefined, - identification_fields: undefined, - list_per_page: undefined, - ordering: QueryOrderingEnum.ASC, - ordering_field: undefined, - readonly_fields: undefined, - sortable_by: undefined, - autocomplete_columns: undefined, - custom_fields: undefined, - table_widgets: undefined, - }; - - const commandData = { - operationType: OperationTypeEnum.validateSettings, - tableName: testTableName, - row: undefined, - primaryKey: undefined, - tableSettings: settings, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result.length).toBe(0); - }); - - it('should return an error array with error when called validate settings operation with wrong search field', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const settings = { - connection_id: faker.string.uuid(), - table_name: testTableName, - display_name: '', - search_fields: [faker.lorem.words(1)], - excluded_fields: undefined, - list_fields: undefined, - identification_fields: undefined, - list_per_page: undefined, - ordering: QueryOrderingEnum.ASC, - ordering_field: undefined, - readonly_fields: undefined, - sortable_by: undefined, - autocomplete_columns: undefined, - custom_fields: undefined, - table_widgets: undefined, - }; - - const commandData = { - operationType: OperationTypeEnum.validateSettings, - tableName: testTableName, - row: undefined, - primaryKey: undefined, - tableSettings: settings, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result.length).toBe(1); - }); - }); - }); -}); diff --git a/rocketadmin-agent/test/command/command-executor-postgres.spec.ts b/rocketadmin-agent/test/command/command-executor-postgres.spec.ts deleted file mode 100644 index 335ec85a..00000000 --- a/rocketadmin-agent/test/command/command-executor-postgres.spec.ts +++ /dev/null @@ -1,715 +0,0 @@ -import { faker } from '@faker-js/faker'; -import { AppModule } from '../../src/app.module.js'; -import { INestApplication } from '@nestjs/common'; -import { Knex, knex } from 'knex'; -import { Test } from '@nestjs/testing'; -import { ICLIConnectionCredentials } from '../../src/interfaces/interfaces.js'; -import { CommandExecutor } from '../../src/command/command-executor.js'; -import { OperationTypeEnum } from '../../src/enums/operation-type.enum.js'; -import { Constants } from '../../src/helpers/constants/constants.js'; -import { QueryOrderingEnum } from '../../src/enums/query-ordering.enum.js'; - -describe('Command executor tests', () => { - let app: INestApplication; - const testTableName = 'users'; - const testTableColumnName = 'name'; - const testTAbleSecondColumnName = 'email'; - const testSearchedUserName = 'Vasia'; - const testEntitiesSeedsCount = 42; - const connectionConfig: ICLIConnectionCredentials = { - cert: '', - database: 'template1', - host: 'localhost', - password: '123', - port: 9002, - schema: '', - sid: '', - ssl: false, - type: 'postgres', - username: 'postgres', - token: 'token', - app_port: 3000, - azure_encryption: false, - application_save_option: false, - config_encryption_option: false, - encryption_password: undefined, - saving_logs_option: false, - }; - - async function resetPostgresTestDB() { - const Knex = knex({ - client: connectionConfig.type, - connection: { - host: connectionConfig.host, - user: connectionConfig.username, - password: connectionConfig.password, - database: connectionConfig.database, - port: 9002, - }, - }); - await Knex.schema.dropTableIfExists(testTableName); - await Knex.schema.createTableIfNotExists(testTableName, function (table) { - table.increments(); - table.string(testTableColumnName); - table.string(testTAbleSecondColumnName); - table.timestamps(); - }); - - for (let i = 0; i < testEntitiesSeedsCount; i++) { - if (i === 0 || i === testEntitiesSeedsCount - 21 || i === testEntitiesSeedsCount - 5) { - await Knex(testTableName).insert({ - [testTableColumnName]: testSearchedUserName, - [testTAbleSecondColumnName]: faker.internet.email(), - created_at: new Date(), - updated_at: new Date(), - }); - } else { - await Knex(testTableName).insert({ - [testTableColumnName]: faker.person.firstName(), - [testTAbleSecondColumnName]: faker.internet.email(), - created_at: new Date(), - updated_at: new Date(), - }); - } - } - await Knex.destroy(); - } - - beforeEach(async () => { - jest.setTimeout(10000); - const moduleFixture = await Test.createTestingModule({ - imports: [AppModule], - }).compile(); - - app = moduleFixture.createNestApplication() as any; - await app.init(); - await resetPostgresTestDB(); - }); - - describe('execute command', () => { - describe('addRowInTable command', () => { - it('should return added row primary key when call add row in table', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const fakeName = faker.person.firstName(); - const fakeMail = faker.internet.email(); - - const row = { - [testTableColumnName]: fakeName, - [testTAbleSecondColumnName]: fakeMail, - }; - - const commandData = { - operationType: OperationTypeEnum.addRowInTable, - tableName: testTableName, - row: row, - primaryKey: undefined, - tableSettings: undefined, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result.id).toBe(43); - }); - - it('should return an error when call add row in table without passed row', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.addRowInTable, - tableName: testTableName, - row: undefined, - primaryKey: undefined, - tableSettings: undefined, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result instanceof Error).toBeTruthy(); - }); - }); - - describe('deleteRowInTable command', () => { - it('should return deleted row primary key when call delete row in table', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.deleteRowInTable, - tableName: testTableName, - row: undefined, - primaryKey: { id: 1 }, - tableSettings: undefined, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result[0].id).toBe(1); - expect(result.length).toBe(1); - }); - - it('should return an error when call delete row in table without primary key', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.deleteRowInTable, - tableName: testTableName, - row: undefined, - primaryKey: undefined, - tableSettings: undefined, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result instanceof Error).toBeTruthy(); - }); - }); - - describe('getRowByPrimaryKey command', () => { - it('should return row by primary key when call get row by primary key', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getRowByPrimaryKey, - tableName: testTableName, - row: undefined, - primaryKey: { id: 1 }, - tableSettings: undefined, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result.length).toBe(1); - expect(result[0].id).toBe(1); - expect(result[0].hasOwnProperty('name')).toBeTruthy(); - expect(result[0].hasOwnProperty('email')).toBeTruthy(); - expect(result[0].hasOwnProperty('created_at')).toBeTruthy(); - expect(result[0].hasOwnProperty('updated_at')).toBeTruthy(); - }); - - it('should return an error when called get row by primary key without primary key', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getRowByPrimaryKey, - tableName: testTableName, - row: undefined, - primaryKey: undefined, - tableSettings: undefined, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result instanceof Error).toBeTruthy(); - }); - }); - - describe('getRowsFromTable command', () => { - it('should return all rows when call get rows ', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getRowsFromTable, - tableName: testTableName, - row: undefined, - primaryKey: undefined, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result.data.length).toBe(20); - expect(result.hasOwnProperty('pagination')); - expect(result.pagination.total).toBe(testEntitiesSeedsCount); - expect(result.pagination.perPage).toBe(Constants.DEFAULT_PAGINATION.perPage); - expect(result.pagination.currentPage).toBe(Constants.DEFAULT_PAGINATION.page); - expect(result.pagination.lastPage).toBe( - Math.ceil(testEntitiesSeedsCount / Constants.DEFAULT_PAGINATION.perPage), - ); - }); - - it('should return an error when call get rows without table name', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getRowsFromTable, - tableName: undefined, - row: undefined, - primaryKey: undefined, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result instanceof Error).toBeTruthy(); - }); - }); - - describe('getTableForeignKeys command', () => { - it('should return all empty foreign keys array when called get table foreign keys', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getTableForeignKeys, - tableName: testTableName, - row: undefined, - primaryKey: undefined, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result.length).toBe(0); - }); - - it('should return an error when called get table foreign keys without table name', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getTableForeignKeys, - tableName: undefined, - row: undefined, - primaryKey: undefined, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result instanceof Error).toBeTruthy(); - }); - }); - - describe('getTablePrimaryColumns command', () => { - it('should return primary keys array when called get table primary column operation', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getTablePrimaryColumns, - tableName: testTableName, - row: undefined, - primaryKey: undefined, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result.length).toBe(1); - expect(result[0].column_name).toBe('id'); - expect(result[0].data_type).toBe('integer'); - }); - - it('should return an error when called get table primary column operation without table name', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getTablePrimaryColumns, - tableName: undefined, - row: undefined, - primaryKey: undefined, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result instanceof Error).toBeTruthy(); - }); - }); - - describe('getTableStructure command', () => { - it('should return table structure when called get table structure operation', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getTableStructure, - tableName: testTableName, - row: undefined, - primaryKey: undefined, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - - expect(result.length).toBe(5); - for (const element of result) { - expect(element.hasOwnProperty('column_name')).toBeTruthy(); - expect(element.hasOwnProperty('column_default')).toBeTruthy(); - expect(element.hasOwnProperty('data_type')).toBeTruthy(); - expect(element.hasOwnProperty('udt_name')).toBeTruthy(); - expect(element.hasOwnProperty('character_maximum_length')).toBeTruthy(); - expect(element.hasOwnProperty('allow_null')).toBeTruthy(); - } - }); - - it('should return an error when called get table structure operation without table name', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getTableStructure, - tableName: undefined, - row: undefined, - primaryKey: undefined, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result instanceof Error).toBeTruthy(); - }); - }); - - describe('getTablesFromDB command', () => { - it('should return tables when called get tables from db operation', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: OperationTypeEnum.getTablesFromDB, - tableName: undefined, - row: undefined, - primaryKey: undefined, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result.length).toBe(1); - expect(result[0]).toBe(testTableName); - }); - - it('should return an exception when called get tables from db operation without operation type', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const commandData = { - operationType: undefined, - tableName: undefined, - row: undefined, - primaryKey: undefined, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result instanceof Error).toBeTruthy(); - }); - }); - - describe('updateRowInTable command', () => { - it('should return updated table row primary key operation', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const fakeName = faker.person.firstName(); - const fakeMail = faker.internet.email(); - - const row = { - [testTableColumnName]: fakeName, - [testTAbleSecondColumnName]: fakeMail, - }; - - const primaryKey = { - id: 1, - }; - - const commandData = { - operationType: OperationTypeEnum.updateRowInTable, - tableName: testTableName, - row: row, - primaryKey: primaryKey, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(JSON.stringify(result)).toBe(JSON.stringify([primaryKey])); - }); - - it('should return when called update row primary operation without row', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const primaryKey = { - id: 1, - }; - - const commandData = { - operationType: OperationTypeEnum.updateRowInTable, - tableName: testTableName, - row: undefined, - primaryKey: primaryKey, - tableSettings: {}, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result instanceof Error).toBeTruthy(); - }); - }); - - describe('validateSettings command', () => { - it('should return empty errors array when called validate settings operation', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const settings = { - connection_id: faker.string.uuid();, - table_name: testTableName, - display_name: '', - search_fields: [testTableColumnName], - excluded_fields: undefined, - list_fields: undefined, - identification_fields: undefined, - list_per_page: undefined, - ordering: QueryOrderingEnum.ASC, - ordering_field: undefined, - readonly_fields: undefined, - sortable_by: undefined, - autocomplete_columns: undefined, - custom_fields: undefined, - table_widgets: undefined, - }; - - const commandData = { - operationType: OperationTypeEnum.validateSettings, - tableName: testTableName, - row: undefined, - primaryKey: undefined, - tableSettings: settings, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result.length).toBe(0); - }); - - it('should return an error array with error when called validate settings operation with wrong search field', async () => { - const commandExecutor = new CommandExecutor(connectionConfig); - - const settings = { - connection_id: faker.string.uuid();, - table_name: testTableName, - display_name: '', - search_fields: [faker.lorem.words(1)], - excluded_fields: undefined, - list_fields: undefined, - identification_fields: undefined, - list_per_page: undefined, - ordering: QueryOrderingEnum.ASC, - ordering_field: undefined, - readonly_fields: undefined, - sortable_by: undefined, - autocomplete_columns: undefined, - custom_fields: undefined, - table_widgets: undefined, - }; - - const commandData = { - operationType: OperationTypeEnum.validateSettings, - tableName: testTableName, - row: undefined, - primaryKey: undefined, - tableSettings: settings, - page: undefined, - perPage: undefined, - searchedFieldValue: undefined, - filteringFields: undefined, - autocompleteFields: undefined, - fieldValues: undefined, - identityColumnName: undefined, - referencedFieldName: undefined, - email: 'test@testmail.com', - }; - - const result = await commandExecutor.executeCommand({ - data: commandData as any, - }); - expect(result.length).toBe(1); - }); - }); - }); -}); diff --git a/rocketadmin-agent/test/jest-e2e.json b/rocketadmin-agent/test/jest-e2e.json deleted file mode 100644 index 3aaafc48..00000000 --- a/rocketadmin-agent/test/jest-e2e.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "moduleFileExtensions": [".js", ".jsx", ".json", ".ts", ".tsx"], - "rootDir": "..", - "testEnvironment": "node", - "testRegex": ".e2e-spec.ts$", - "transform": { - "^.+\\.(t|j)s$": "ts-jest" - } -} \ No newline at end of file diff --git a/shared-code/src/data-access-layer/data-access-objects/data-access-object-agent.ts b/shared-code/src/data-access-layer/data-access-objects/data-access-object-agent.ts index ba20226b..8dae5a86 100644 --- a/shared-code/src/data-access-layer/data-access-objects/data-access-object-agent.ts +++ b/shared-code/src/data-access-layer/data-access-objects/data-access-object-agent.ts @@ -13,8 +13,8 @@ import { TableSettingsDS } from '../shared/data-structures/table-settings.ds.js' import { TableStructureDS } from '../shared/data-structures/table-structure.ds.js'; import { TestConnectionResultDS } from '../shared/data-structures/test-result-connection.ds.js'; import { ValidateTableSettingsDS } from '../shared/data-structures/validate-table-settings.ds.js'; -import { IDataAccessObjectAgent } from '../shared/interfaces/data-access-object-agent.interface.js'; -import { DataAccessObjectCommandsEnum } from '../shared/enums/data-access-object-commands.enum.js'; +import { IDataAccessObjectAgent } from '../../shared/interfaces/data-access-object-agent.interface.js'; +import { DataAccessObjectCommandsEnum } from '../../shared/enums/data-access-object-commands.enum.js'; import { LRUStorage } from '../../caching/lru-storage.js'; import { TableDS } from '../shared/data-structures/table.ds.js'; import { Stream, Readable } from 'node:stream'; @@ -30,7 +30,7 @@ import { isPostgresDateOrTimeType, isPostgresDateStringByRegexp, } from '../../helpers/is-database-date.js'; -import { ConnectionTypesEnum } from '../shared/enums/connection-types-enum.js'; +import { ConnectionTypesEnum } from '../../shared/enums/connection-types-enum.js'; export class DataAccessObjectAgent implements IDataAccessObjectAgent { private readonly connection: ConnectionAgentParams; diff --git a/shared-code/src/data-access-layer/data-access-objects/data-access-object-cassandra.ts b/shared-code/src/data-access-layer/data-access-objects/data-access-object-cassandra.ts index bd4d5edd..962f3346 100644 --- a/shared-code/src/data-access-layer/data-access-objects/data-access-object-cassandra.ts +++ b/shared-code/src/data-access-layer/data-access-objects/data-access-object-cassandra.ts @@ -20,9 +20,9 @@ import { TableStructureDS } from '../shared/data-structures/table-structure.ds.j import { TableDS } from '../shared/data-structures/table.ds.js'; import { TestConnectionResultDS } from '../shared/data-structures/test-result-connection.ds.js'; import { ValidateTableSettingsDS } from '../shared/data-structures/validate-table-settings.ds.js'; -import { FilterCriteriaEnum } from '../shared/enums/filter-criteria.enum.js'; -import { QueryOrderingEnum } from '../shared/enums/query-ordering.enum.js'; -import { IDataAccessObject } from '../shared/interfaces/data-access-object.interface.js'; +import { FilterCriteriaEnum } from '../../shared/enums/filter-criteria.enum.js'; +import { QueryOrderingEnum } from '../../shared/enums/query-ordering.enum.js'; +import { IDataAccessObject } from '../../shared/interfaces/data-access-object.interface.js'; import { BasicDataAccessObject } from './basic-data-access-object.js'; export class DataAccessObjectCassandra extends BasicDataAccessObject implements IDataAccessObject { diff --git a/shared-code/src/data-access-layer/data-access-objects/data-access-object-clickhouse.ts b/shared-code/src/data-access-layer/data-access-objects/data-access-object-clickhouse.ts index a45e5c78..e52ba08e 100644 --- a/shared-code/src/data-access-layer/data-access-objects/data-access-object-clickhouse.ts +++ b/shared-code/src/data-access-layer/data-access-objects/data-access-object-clickhouse.ts @@ -18,8 +18,8 @@ import { TableStructureDS } from '../shared/data-structures/table-structure.ds.j import { TableDS } from '../shared/data-structures/table.ds.js'; import { TestConnectionResultDS } from '../shared/data-structures/test-result-connection.ds.js'; import { ValidateTableSettingsDS } from '../shared/data-structures/validate-table-settings.ds.js'; -import { FilterCriteriaEnum } from '../shared/enums/filter-criteria.enum.js'; -import { IDataAccessObject } from '../shared/interfaces/data-access-object.interface.js'; +import { FilterCriteriaEnum } from '../../shared/enums/filter-criteria.enum.js'; +import { IDataAccessObject } from '../../shared/interfaces/data-access-object.interface.js'; import { BasicDataAccessObject } from './basic-data-access-object.js'; import { NodeClickHouseClientConfigOptions } from '@clickhouse/client/dist/config.js'; diff --git a/shared-code/src/data-access-layer/data-access-objects/data-access-object-dynamodb.ts b/shared-code/src/data-access-layer/data-access-objects/data-access-object-dynamodb.ts index 43f5e28b..21a0c94b 100644 --- a/shared-code/src/data-access-layer/data-access-objects/data-access-object-dynamodb.ts +++ b/shared-code/src/data-access-layer/data-access-objects/data-access-object-dynamodb.ts @@ -28,9 +28,9 @@ import { DynamoDBType, TableStructureDS } from '../shared/data-structures/table- import { TableDS } from '../shared/data-structures/table.ds.js'; import { TestConnectionResultDS } from '../shared/data-structures/test-result-connection.ds.js'; import { ValidateTableSettingsDS } from '../shared/data-structures/validate-table-settings.ds.js'; -import { FilterCriteriaEnum } from '../shared/enums/filter-criteria.enum.js'; -import { QueryOrderingEnum } from '../shared/enums/query-ordering.enum.js'; -import { IDataAccessObject } from '../shared/interfaces/data-access-object.interface.js'; +import { FilterCriteriaEnum } from '../../shared/enums/filter-criteria.enum.js'; +import { QueryOrderingEnum } from '../../shared/enums/query-ordering.enum.js'; +import { IDataAccessObject } from '../../shared/interfaces/data-access-object.interface.js'; import { BasicDataAccessObject } from './basic-data-access-object.js'; export type DdAndClient = { diff --git a/shared-code/src/data-access-layer/data-access-objects/data-access-object-elasticsearch.ts b/shared-code/src/data-access-layer/data-access-objects/data-access-object-elasticsearch.ts index e132d663..d49323b8 100644 --- a/shared-code/src/data-access-layer/data-access-objects/data-access-object-elasticsearch.ts +++ b/shared-code/src/data-access-layer/data-access-objects/data-access-object-elasticsearch.ts @@ -16,8 +16,8 @@ import { TableStructureDS } from '../shared/data-structures/table-structure.ds.j import { TableDS } from '../shared/data-structures/table.ds.js'; import { TestConnectionResultDS } from '../shared/data-structures/test-result-connection.ds.js'; import { ValidateTableSettingsDS } from '../shared/data-structures/validate-table-settings.ds.js'; -import { FilterCriteriaEnum } from '../shared/enums/filter-criteria.enum.js'; -import { IDataAccessObject } from '../shared/interfaces/data-access-object.interface.js'; +import { FilterCriteriaEnum } from '../../shared/enums/filter-criteria.enum.js'; +import { IDataAccessObject } from '../../shared/interfaces/data-access-object.interface.js'; import { BasicDataAccessObject } from './basic-data-access-object.js'; export class DataAccessObjectElasticsearch extends BasicDataAccessObject implements IDataAccessObject { diff --git a/shared-code/src/data-access-layer/data-access-objects/data-access-object-ibmdb2.ts b/shared-code/src/data-access-layer/data-access-objects/data-access-object-ibmdb2.ts index 57c37bb3..a954863a 100644 --- a/shared-code/src/data-access-layer/data-access-objects/data-access-object-ibmdb2.ts +++ b/shared-code/src/data-access-layer/data-access-objects/data-access-object-ibmdb2.ts @@ -20,8 +20,8 @@ import { TableStructureDS } from '../shared/data-structures/table-structure.ds.j import { TableDS } from '../shared/data-structures/table.ds.js'; import { TestConnectionResultDS } from '../shared/data-structures/test-result-connection.ds.js'; import { ValidateTableSettingsDS } from '../shared/data-structures/validate-table-settings.ds.js'; -import { FilterCriteriaEnum } from '../shared/enums/filter-criteria.enum.js'; -import { IDataAccessObject } from '../shared/interfaces/data-access-object.interface.js'; +import { FilterCriteriaEnum } from '../../shared/enums/filter-criteria.enum.js'; +import { IDataAccessObject } from '../../shared/interfaces/data-access-object.interface.js'; import { BasicDataAccessObject } from './basic-data-access-object.js'; export class DataAccessObjectIbmDb2 extends BasicDataAccessObject implements IDataAccessObject { diff --git a/shared-code/src/data-access-layer/data-access-objects/data-access-object-mongodb.ts b/shared-code/src/data-access-layer/data-access-objects/data-access-object-mongodb.ts index 00c6130e..eca9fbb6 100644 --- a/shared-code/src/data-access-layer/data-access-objects/data-access-object-mongodb.ts +++ b/shared-code/src/data-access-layer/data-access-objects/data-access-object-mongodb.ts @@ -23,8 +23,8 @@ import { TableStructureDS } from '../shared/data-structures/table-structure.ds.j import { TableDS } from '../shared/data-structures/table.ds.js'; import { TestConnectionResultDS } from '../shared/data-structures/test-result-connection.ds.js'; import { ValidateTableSettingsDS } from '../shared/data-structures/validate-table-settings.ds.js'; -import { FilterCriteriaEnum } from '../shared/enums/filter-criteria.enum.js'; -import { IDataAccessObject } from '../shared/interfaces/data-access-object.interface.js'; +import { FilterCriteriaEnum } from '../../shared/enums/filter-criteria.enum.js'; +import { IDataAccessObject } from '../../shared/interfaces/data-access-object.interface.js'; import { BasicDataAccessObject } from './basic-data-access-object.js'; export type MongoClientDB = { diff --git a/shared-code/src/data-access-layer/data-access-objects/data-access-object-mssql.ts b/shared-code/src/data-access-layer/data-access-objects/data-access-object-mssql.ts index f3d2c8a4..ec2a11e4 100644 --- a/shared-code/src/data-access-layer/data-access-objects/data-access-object-mssql.ts +++ b/shared-code/src/data-access-layer/data-access-objects/data-access-object-mssql.ts @@ -22,9 +22,9 @@ import { TableStructureDS } from '../shared/data-structures/table-structure.ds.j import { TableDS } from '../shared/data-structures/table.ds.js'; import { TestConnectionResultDS } from '../shared/data-structures/test-result-connection.ds.js'; import { ValidateTableSettingsDS } from '../shared/data-structures/validate-table-settings.ds.js'; -import { FilterCriteriaEnum } from '../shared/enums/filter-criteria.enum.js'; -import { QueryOrderingEnum } from '../shared/enums/query-ordering.enum.js'; -import { IDataAccessObject } from '../shared/interfaces/data-access-object.interface.js'; +import { FilterCriteriaEnum } from '../../shared/enums/filter-criteria.enum.js'; +import { QueryOrderingEnum } from '../../shared/enums/query-ordering.enum.js'; +import { IDataAccessObject } from '../../shared/interfaces/data-access-object.interface.js'; import { BasicDataAccessObject } from './basic-data-access-object.js'; export class DataAccessObjectMssql extends BasicDataAccessObject implements IDataAccessObject { diff --git a/shared-code/src/data-access-layer/data-access-objects/data-access-object-mysql.ts b/shared-code/src/data-access-layer/data-access-objects/data-access-object-mysql.ts index 95594eff..d9ff06de 100644 --- a/shared-code/src/data-access-layer/data-access-objects/data-access-object-mysql.ts +++ b/shared-code/src/data-access-layer/data-access-objects/data-access-object-mysql.ts @@ -15,8 +15,8 @@ import { TableSettingsDS } from '../shared/data-structures/table-settings.ds.js' import { TableStructureDS } from '../shared/data-structures/table-structure.ds.js'; import { TestConnectionResultDS } from '../shared/data-structures/test-result-connection.ds.js'; import { ValidateTableSettingsDS } from '../shared/data-structures/validate-table-settings.ds.js'; -import { FilterCriteriaEnum } from '../shared/enums/filter-criteria.enum.js'; -import { IDataAccessObject } from '../shared/interfaces/data-access-object.interface.js'; +import { FilterCriteriaEnum } from '../../shared/enums/filter-criteria.enum.js'; +import { IDataAccessObject } from '../../shared/interfaces/data-access-object.interface.js'; import { BasicDataAccessObject } from './basic-data-access-object.js'; import { objectKeysToLowercase } from '../../helpers/object-kyes-to-lowercase.js'; import { Knex } from 'knex'; diff --git a/shared-code/src/data-access-layer/data-access-objects/data-access-object-oracle.ts b/shared-code/src/data-access-layer/data-access-objects/data-access-object-oracle.ts index 8324357b..d4698073 100644 --- a/shared-code/src/data-access-layer/data-access-objects/data-access-object-oracle.ts +++ b/shared-code/src/data-access-layer/data-access-objects/data-access-object-oracle.ts @@ -27,8 +27,8 @@ import { TableStructureDS } from '../shared/data-structures/table-structure.ds.j import { TableDS } from '../shared/data-structures/table.ds.js'; import { TestConnectionResultDS } from '../shared/data-structures/test-result-connection.ds.js'; import { ValidateTableSettingsDS } from '../shared/data-structures/validate-table-settings.ds.js'; -import { FilterCriteriaEnum } from '../shared/enums/filter-criteria.enum.js'; -import { IDataAccessObject } from '../shared/interfaces/data-access-object.interface.js'; +import { FilterCriteriaEnum } from '../../shared/enums/filter-criteria.enum.js'; +import { IDataAccessObject } from '../../shared/interfaces/data-access-object.interface.js'; import { BasicDataAccessObject } from './basic-data-access-object.js'; type RefererencedConstraint = { @@ -494,7 +494,8 @@ export class DataAccessObjectOracle extends BasicDataAccessObject implements IDa } const knex = await this.configureKnex(); const schema = this.connection.schema ?? this.connection.username.toUpperCase(); - const structureColumns = await knex.queryBuilder() + const structureColumns = await knex + .queryBuilder() .select('COLUMN_NAME', 'DATA_DEFAULT', 'DATA_TYPE', 'NULLABLE', 'DATA_LENGTH') .from('ALL_TAB_COLUMNS') .orderBy('COLUMN_ID') diff --git a/shared-code/src/data-access-layer/data-access-objects/data-access-object-postgres.ts b/shared-code/src/data-access-layer/data-access-objects/data-access-object-postgres.ts index 1787a4e5..53ca9515 100644 --- a/shared-code/src/data-access-layer/data-access-objects/data-access-object-postgres.ts +++ b/shared-code/src/data-access-layer/data-access-objects/data-access-object-postgres.ts @@ -19,8 +19,8 @@ import { TableStructureDS } from '../shared/data-structures/table-structure.ds.j import { TableDS } from '../shared/data-structures/table.ds.js'; import { TestConnectionResultDS } from '../shared/data-structures/test-result-connection.ds.js'; import { ValidateTableSettingsDS } from '../shared/data-structures/validate-table-settings.ds.js'; -import { FilterCriteriaEnum } from '../shared/enums/filter-criteria.enum.js'; -import { IDataAccessObject } from '../shared/interfaces/data-access-object.interface.js'; +import { FilterCriteriaEnum } from '../../shared/enums/filter-criteria.enum.js'; +import { IDataAccessObject } from '../../shared/interfaces/data-access-object.interface.js'; import { BasicDataAccessObject } from './basic-data-access-object.js'; import { nanoid } from 'nanoid'; diff --git a/shared-code/src/data-access-layer/data-access-objects/data-access-object-redis.ts b/shared-code/src/data-access-layer/data-access-objects/data-access-object-redis.ts index 7dbe8fb0..ce9fa2e3 100644 --- a/shared-code/src/data-access-layer/data-access-objects/data-access-object-redis.ts +++ b/shared-code/src/data-access-layer/data-access-objects/data-access-object-redis.ts @@ -19,8 +19,8 @@ import { TableStructureDS } from '../shared/data-structures/table-structure.ds.j import { TableDS } from '../shared/data-structures/table.ds.js'; import { TestConnectionResultDS } from '../shared/data-structures/test-result-connection.ds.js'; import { ValidateTableSettingsDS } from '../shared/data-structures/validate-table-settings.ds.js'; -import { FilterCriteriaEnum } from '../shared/enums/filter-criteria.enum.js'; -import { IDataAccessObject } from '../shared/interfaces/data-access-object.interface.js'; +import { FilterCriteriaEnum } from '../../shared/enums/filter-criteria.enum.js'; +import { IDataAccessObject } from '../../shared/interfaces/data-access-object.interface.js'; import { BasicDataAccessObject } from './basic-data-access-object.js'; import { isRedisConnectionUrl } from '../shared/create-data-access-object.js'; diff --git a/shared-code/src/data-access-layer/shared/create-data-access-object.ts b/shared-code/src/data-access-layer/shared/create-data-access-object.ts index eccd7409..8e20457c 100644 --- a/shared-code/src/data-access-layer/shared/create-data-access-object.ts +++ b/shared-code/src/data-access-layer/shared/create-data-access-object.ts @@ -12,9 +12,9 @@ import { DataAccessObjectOracle } from '../data-access-objects/data-access-objec import { DataAccessObjectPostgres } from '../data-access-objects/data-access-object-postgres.js'; import { DataAccessObjectRedis } from '../data-access-objects/data-access-object-redis.js'; import { ConnectionAgentParams, ConnectionParams } from './data-structures/connections-params.ds.js'; -import { ConnectionTypesEnum } from './enums/connection-types-enum.js'; -import { IDataAccessObjectAgent } from './interfaces/data-access-object-agent.interface.js'; -import { IDataAccessObject } from './interfaces/data-access-object.interface.js'; +import { ConnectionTypesEnum } from '../../shared/enums/connection-types-enum.js'; +import { IDataAccessObjectAgent } from '../../shared/interfaces/data-access-object-agent.interface.js'; +import { IDataAccessObject } from '../../shared/interfaces/data-access-object.interface.js'; interface IUnknownConnectionParams { [key: string]: any; diff --git a/shared-code/src/data-access-layer/shared/data-structures/filtering-fields.ds.ts b/shared-code/src/data-access-layer/shared/data-structures/filtering-fields.ds.ts index d8a86009..e9faf9e5 100644 --- a/shared-code/src/data-access-layer/shared/data-structures/filtering-fields.ds.ts +++ b/shared-code/src/data-access-layer/shared/data-structures/filtering-fields.ds.ts @@ -1,4 +1,4 @@ -import { FilterCriteriaEnum } from '../enums/filter-criteria.enum.js'; +import { FilterCriteriaEnum } from '../../../shared/enums/filter-criteria.enum.js'; export class FilteringFieldsDS { field: string; diff --git a/shared-code/src/data-access-layer/shared/data-structures/table-settings.ds.ts b/shared-code/src/data-access-layer/shared/data-structures/table-settings.ds.ts index fc3a1914..22902366 100644 --- a/shared-code/src/data-access-layer/shared/data-structures/table-settings.ds.ts +++ b/shared-code/src/data-access-layer/shared/data-structures/table-settings.ds.ts @@ -1,4 +1,4 @@ -import { QueryOrderingEnum } from '../enums/query-ordering.enum.js'; +import { QueryOrderingEnum } from '../../../shared/enums/query-ordering.enum.js'; export class TableSettingsDS { table_name: string; diff --git a/shared-code/src/data-access-layer/shared/data-structures/table-widget.ds.ts b/shared-code/src/data-access-layer/shared/data-structures/table-widget.ds.ts index 65c558f2..b082f61a 100644 --- a/shared-code/src/data-access-layer/shared/data-structures/table-widget.ds.ts +++ b/shared-code/src/data-access-layer/shared/data-structures/table-widget.ds.ts @@ -1,4 +1,4 @@ -import { TableWidgetTypeEnum } from '../enums/table-widget-type.enum.js'; +import { TableWidgetTypeEnum } from '../../../shared/enums/table-widget-type.enum.js'; export class TableWidgetDS { id: string; diff --git a/shared-code/src/data-access-layer/shared/data-structures/validate-table-settings.ds.ts b/shared-code/src/data-access-layer/shared/data-structures/validate-table-settings.ds.ts index b4234c0c..9742cd5b 100644 --- a/shared-code/src/data-access-layer/shared/data-structures/validate-table-settings.ds.ts +++ b/shared-code/src/data-access-layer/shared/data-structures/validate-table-settings.ds.ts @@ -1,4 +1,4 @@ -import { QueryOrderingEnum } from '../enums/query-ordering.enum.js'; +import { QueryOrderingEnum } from '../../../shared/enums/query-ordering.enum.js'; import { CustomFieldDS } from './custom-field.ds.js'; import { TableWidgetDS } from './table-widget.ds.js'; diff --git a/shared-code/src/data-access-layer/shared/enums/connection-types-enum.ts b/shared-code/src/data-access-layer/shared/enums/connection-types-enum.ts deleted file mode 100644 index 1ee1bc90..00000000 --- a/shared-code/src/data-access-layer/shared/enums/connection-types-enum.ts +++ /dev/null @@ -1,23 +0,0 @@ -export enum ConnectionTypesEnum { - postgres = 'postgres', - mysql = 'mysql', - mysql2 = 'mysql2', - oracledb = 'oracledb', - mssql = 'mssql', - ibmdb2 = 'ibmdb2', - mongodb = 'mongodb', - dynamodb = 'dynamodb', - elasticsearch = 'elasticsearch', - cassandra = 'cassandra', - redis = 'redis', - clickhouse = 'clickhouse', - agent_postgres = 'agent_postgres', - agent_mysql = 'agent_mysql', - agent_oracledb = 'agent_oracledb', - agent_mssql = 'agent_mssql', - agent_ibmdb2 = 'agent_ibmdb2', - agent_mongodb = 'agent_mongodb', - agent_cassandra = 'agent_cassandra', - agent_redis = 'agent_redis', - agent_clickhouse = 'agent_clickhouse', -} diff --git a/shared-code/src/helpers/data-structures-builders/table-widget-ds.builder.ts b/shared-code/src/helpers/data-structures-builders/table-widget-ds.builder.ts index 9b2f4437..2131da85 100644 --- a/shared-code/src/helpers/data-structures-builders/table-widget-ds.builder.ts +++ b/shared-code/src/helpers/data-structures-builders/table-widget-ds.builder.ts @@ -1,5 +1,5 @@ import { TableWidgetDS } from '../../data-access-layer/shared/data-structures/table-widget.ds.js'; -import { IUnknownDataStructure } from '../../data-access-layer/shared/interfaces/unknown-datastructure.interface.js'; +import { IUnknownDataStructure } from '../../shared/interfaces/unknown-datastructure.interface.js'; export function buildTableWidgetDs(tableWidgetParams: IUnknownDataStructure): TableWidgetDS { return { diff --git a/shared-code/src/helpers/data-structures-builders/validate-table-settings-ds.builder.ts b/shared-code/src/helpers/data-structures-builders/validate-table-settings-ds.builder.ts index 2a4e96b5..3ecf6e72 100644 --- a/shared-code/src/helpers/data-structures-builders/validate-table-settings-ds.builder.ts +++ b/shared-code/src/helpers/data-structures-builders/validate-table-settings-ds.builder.ts @@ -1,5 +1,5 @@ import { ValidateTableSettingsDS } from '../../data-access-layer/shared/data-structures/validate-table-settings.ds.js'; -import { IUnknownDataStructure } from '../../data-access-layer/shared/interfaces/unknown-datastructure.interface.js'; +import { IUnknownDataStructure } from '../../shared/interfaces/unknown-datastructure.interface.js'; import { buildTableWidgetDs } from './table-widget-ds.builder.js'; export function buildValidateTableSettingsDS(tableSettings: IUnknownDataStructure): ValidateTableSettingsDS { diff --git a/shared-code/src/helpers/validation/table-settings-validation-errors.ts b/shared-code/src/helpers/validation/table-settings-validation-errors.ts index 41c64347..b2eb561d 100644 --- a/shared-code/src/helpers/validation/table-settings-validation-errors.ts +++ b/shared-code/src/helpers/validation/table-settings-validation-errors.ts @@ -1,4 +1,4 @@ -import { QueryOrderingEnum } from '../../data-access-layer/shared/enums/query-ordering.enum.js'; +import { QueryOrderingEnum } from '../../shared/enums/query-ordering.enum.js'; import { enumToString } from '../../helpers/enum-to-string.js'; export const TABLE_SETTINGS_VALIDATION_ERRORS = { diff --git a/shared-code/src/helpers/validation/table-settings-validator.ts b/shared-code/src/helpers/validation/table-settings-validator.ts index ec9ae560..c3424a4b 100644 --- a/shared-code/src/helpers/validation/table-settings-validator.ts +++ b/shared-code/src/helpers/validation/table-settings-validator.ts @@ -1,7 +1,7 @@ import { PrimaryKeyDS } from '../../data-access-layer/shared/data-structures/primary-key.ds.js'; import { TableSettingsDS } from '../../data-access-layer/shared/data-structures/table-settings.ds.js'; import { ValidateTableSettingsDS } from '../../data-access-layer/shared/data-structures/validate-table-settings.ds.js'; -import { QueryOrderingEnum } from '../../data-access-layer/shared/enums/query-ordering.enum.js'; +import { QueryOrderingEnum } from '../../shared/enums/query-ordering.enum.js'; import { isObjectEmpty } from '../is-object-empty.js'; import { TABLE_SETTINGS_VALIDATION_ERRORS } from './table-settings-validation-errors.js'; @@ -10,7 +10,6 @@ export function tableSettingsFieldValidator( primaryColumns: Array, settings: ValidateTableSettingsDS | TableSettingsDS, ): Array { - const errorMessages = []; if (isObjectEmpty(settings)) { return errorMessages; @@ -150,5 +149,4 @@ export function tableSettingsFieldValidator( } return errorMessages; - } diff --git a/backend/src/enums/connection-type.enum.ts b/shared-code/src/shared/enums/connection-types-enum.ts similarity index 51% rename from backend/src/enums/connection-type.enum.ts rename to shared-code/src/shared/enums/connection-types-enum.ts index 72462891..adc0f83b 100644 --- a/backend/src/enums/connection-type.enum.ts +++ b/shared-code/src/shared/enums/connection-types-enum.ts @@ -1,3 +1,27 @@ +export enum ConnectionTypesEnum { + postgres = 'postgres', + mysql = 'mysql', + mysql2 = 'mysql2', + oracledb = 'oracledb', + mssql = 'mssql', + ibmdb2 = 'ibmdb2', + mongodb = 'mongodb', + dynamodb = 'dynamodb', + elasticsearch = 'elasticsearch', + cassandra = 'cassandra', + redis = 'redis', + clickhouse = 'clickhouse', + agent_postgres = 'agent_postgres', + agent_mysql = 'agent_mysql', + agent_oracledb = 'agent_oracledb', + agent_mssql = 'agent_mssql', + agent_ibmdb2 = 'agent_ibmdb2', + agent_mongodb = 'agent_mongodb', + agent_cassandra = 'agent_cassandra', + agent_redis = 'agent_redis', + agent_clickhouse = 'agent_clickhouse', +} + export enum ConnectionTypeTestEnum { postgres = 'postgres', mysql = 'mysql', diff --git a/shared-code/src/data-access-layer/shared/enums/data-access-object-commands.enum.ts b/shared-code/src/shared/enums/data-access-object-commands.enum.ts similarity index 100% rename from shared-code/src/data-access-layer/shared/enums/data-access-object-commands.enum.ts rename to shared-code/src/shared/enums/data-access-object-commands.enum.ts diff --git a/shared-code/src/data-access-layer/shared/enums/filter-criteria.enum.ts b/shared-code/src/shared/enums/filter-criteria.enum.ts similarity index 100% rename from shared-code/src/data-access-layer/shared/enums/filter-criteria.enum.ts rename to shared-code/src/shared/enums/filter-criteria.enum.ts diff --git a/shared-code/src/data-access-layer/shared/enums/query-ordering.enum.ts b/shared-code/src/shared/enums/query-ordering.enum.ts similarity index 100% rename from shared-code/src/data-access-layer/shared/enums/query-ordering.enum.ts rename to shared-code/src/shared/enums/query-ordering.enum.ts diff --git a/shared-code/src/data-access-layer/shared/enums/table-widget-type.enum.ts b/shared-code/src/shared/enums/table-widget-type.enum.ts similarity index 100% rename from shared-code/src/data-access-layer/shared/enums/table-widget-type.enum.ts rename to shared-code/src/shared/enums/table-widget-type.enum.ts diff --git a/shared-code/src/data-access-layer/shared/interfaces/data-access-object-agent.interface.ts b/shared-code/src/shared/interfaces/data-access-object-agent.interface.ts similarity index 72% rename from shared-code/src/data-access-layer/shared/interfaces/data-access-object-agent.interface.ts rename to shared-code/src/shared/interfaces/data-access-object-agent.interface.ts index a0d0325a..d233b9a3 100644 --- a/shared-code/src/data-access-layer/shared/interfaces/data-access-object-agent.interface.ts +++ b/shared-code/src/shared/interfaces/data-access-object-agent.interface.ts @@ -1,14 +1,14 @@ -import { AutocompleteFieldsDS } from '../data-structures/autocomplete-fields.ds.js'; -import { FilteringFieldsDS } from '../data-structures/filtering-fields.ds.js'; -import { ForeignKeyDS } from '../data-structures/foreign-key.ds.js'; -import { FoundRowsDS } from '../data-structures/found-rows.ds.js'; -import { PrimaryKeyDS } from '../data-structures/primary-key.ds.js'; -import { ReferencedTableNamesAndColumnsDS } from '../data-structures/referenced-table-names-columns.ds.js'; -import { TableSettingsDS } from '../data-structures/table-settings.ds.js'; -import { TableStructureDS } from '../data-structures/table-structure.ds.js'; -import { TableDS } from '../data-structures/table.ds.js'; -import { TestConnectionResultDS } from '../data-structures/test-result-connection.ds.js'; -import { ValidateTableSettingsDS } from '../data-structures/validate-table-settings.ds.js'; +import { AutocompleteFieldsDS } from '../../data-access-layer/shared/data-structures/autocomplete-fields.ds.js'; +import { FilteringFieldsDS } from '../../data-access-layer/shared/data-structures/filtering-fields.ds.js'; +import { ForeignKeyDS } from '../../data-access-layer/shared/data-structures/foreign-key.ds.js'; +import { FoundRowsDS } from '../../data-access-layer/shared/data-structures/found-rows.ds.js'; +import { PrimaryKeyDS } from '../../data-access-layer/shared/data-structures/primary-key.ds.js'; +import { ReferencedTableNamesAndColumnsDS } from '../../data-access-layer/shared/data-structures/referenced-table-names-columns.ds.js'; +import { TableSettingsDS } from '../../data-access-layer/shared/data-structures/table-settings.ds.js'; +import { TableStructureDS } from '../../data-access-layer/shared/data-structures/table-structure.ds.js'; +import { TableDS } from '../../data-access-layer/shared/data-structures/table.ds.js'; +import { TestConnectionResultDS } from '../../data-access-layer/shared/data-structures/test-result-connection.ds.js'; +import { ValidateTableSettingsDS } from '../../data-access-layer/shared/data-structures/validate-table-settings.ds.js'; import { Stream } from 'node:stream'; export interface IDataAccessObjectAgent { diff --git a/shared-code/src/data-access-layer/shared/interfaces/data-access-object.interface.ts b/shared-code/src/shared/interfaces/data-access-object.interface.ts similarity index 68% rename from shared-code/src/data-access-layer/shared/interfaces/data-access-object.interface.ts rename to shared-code/src/shared/interfaces/data-access-object.interface.ts index b4bb9494..ede9cae8 100644 --- a/shared-code/src/data-access-layer/shared/interfaces/data-access-object.interface.ts +++ b/shared-code/src/shared/interfaces/data-access-object.interface.ts @@ -1,14 +1,14 @@ -import { AutocompleteFieldsDS } from '../data-structures/autocomplete-fields.ds.js'; -import { FilteringFieldsDS } from '../data-structures/filtering-fields.ds.js'; -import { ForeignKeyDS } from '../data-structures/foreign-key.ds.js'; -import { FoundRowsDS } from '../data-structures/found-rows.ds.js'; -import { PrimaryKeyDS } from '../data-structures/primary-key.ds.js'; -import { ReferencedTableNamesAndColumnsDS } from '../data-structures/referenced-table-names-columns.ds.js'; -import { TableSettingsDS } from '../data-structures/table-settings.ds.js'; -import { TableStructureDS } from '../data-structures/table-structure.ds.js'; -import { TestConnectionResultDS } from '../data-structures/test-result-connection.ds.js'; -import { ValidateTableSettingsDS } from '../data-structures/validate-table-settings.ds.js'; -import { TableDS } from '../data-structures/table.ds.js'; +import { AutocompleteFieldsDS } from '../../data-access-layer/shared/data-structures/autocomplete-fields.ds.js'; +import { FilteringFieldsDS } from '../../data-access-layer/shared/data-structures/filtering-fields.ds.js'; +import { ForeignKeyDS } from '../../data-access-layer/shared/data-structures/foreign-key.ds.js'; +import { FoundRowsDS } from '../../data-access-layer/shared/data-structures/found-rows.ds.js'; +import { PrimaryKeyDS } from '../../data-access-layer/shared/data-structures/primary-key.ds.js'; +import { ReferencedTableNamesAndColumnsDS } from '../../data-access-layer/shared/data-structures/referenced-table-names-columns.ds.js'; +import { TableSettingsDS } from '../../data-access-layer/shared/data-structures/table-settings.ds.js'; +import { TableStructureDS } from '../../data-access-layer/shared/data-structures/table-structure.ds.js'; +import { TestConnectionResultDS } from '../../data-access-layer/shared/data-structures/test-result-connection.ds.js'; +import { ValidateTableSettingsDS } from '../../data-access-layer/shared/data-structures/validate-table-settings.ds.js'; +import { TableDS } from '../../data-access-layer/shared/data-structures/table.ds.js'; import { Stream } from 'node:stream'; export interface IDataAccessObject { diff --git a/shared-code/src/data-access-layer/shared/interfaces/unknown-datastructure.interface.ts b/shared-code/src/shared/interfaces/unknown-datastructure.interface.ts similarity index 100% rename from shared-code/src/data-access-layer/shared/interfaces/unknown-datastructure.interface.ts rename to shared-code/src/shared/interfaces/unknown-datastructure.interface.ts