import type {NavigationTreeNodeType} from 'ydb-ui-components'; import {EIndexType, EPathSubType, EPathType} from '../../../types/api/schema'; import type {ETenantType} from '../../../types/api/tenant'; import i18n from '../i18n'; // this file contains verbose mappings that are typed in a way that ensures // correctness when a new node type or a new path type is added // TS will error if a new entity is added but not mapped here const pathSubTypeToNodeType: Record = { [EPathSubType.EPathSubTypeSyncIndexImplTable]: 'index_table', [EPathSubType.EPathSubTypeAsyncIndexImplTable]: 'index_table', [EPathSubType.EPathSubTypeVectorKmeansTreeIndexImplTable]: 'index_table', [EPathSubType.EPathSubTypeFulltextIndexImplTable]: 'index_table', [EPathSubType.EPathSubTypeLocalMinMaxIndex]: undefined, [EPathSubType.EPathSubTypeStreamImpl]: undefined, [EPathSubType.EPathSubTypeEmpty]: undefined, }; const pathTypeToNodeType: Record = { [EPathType.EPathTypeInvalid]: undefined, [EPathType.EPathTypeSubDomain]: 'database', [EPathType.EPathTypeExtSubDomain]: 'database', [EPathType.EPathTypeDir]: 'directory', [EPathType.EPathTypeColumnStore]: 'directory', [EPathType.EPathTypeTable]: 'table', [EPathType.EPathTypeSysView]: 'system_table', [EPathType.EPathTypeTableIndex]: 'index', [EPathType.EPathTypeColumnTable]: 'column_table', [EPathType.EPathTypeCdcStream]: 'stream', [EPathType.EPathTypePersQueueGroup]: 'topic', [EPathType.EPathTypeExternalDataSource]: 'external_data_source', [EPathType.EPathTypeExternalTable]: 'external_table', [EPathType.EPathTypeView]: 'view', [EPathType.EPathTypeReplication]: 'async_replication', [EPathType.EPathTypeTransfer]: 'transfer', [EPathType.EPathTypeResourcePool]: 'resource_pool', [EPathType.EPathTypeSecret]: 'secret', [EPathType.EPathTypeStreamingQuery]: 'streaming_query', }; export const nodeTableTypeToPathType: Partial> = { table: EPathType.EPathTypeTable, system_table: EPathType.EPathTypeSysView, index: EPathType.EPathTypeTableIndex, column_table: EPathType.EPathTypeColumnTable, external_table: EPathType.EPathTypeExternalTable, view: EPathType.EPathTypeView, }; export const tableTypeToPathType: Partial> = { table: EPathType.EPathTypeTable, column_table: EPathType.EPathTypeColumnTable, }; export const rowTableNodeTypeToPathType: Partial> = { table: EPathType.EPathTypeTable, }; export const nodeStreamingQueryTypeToPathType: Partial> = { streaming_query: EPathType.EPathTypeStreamingQuery, }; export const mapPathTypeToNavigationTreeType = ( type: EPathType = EPathType.EPathTypeDir, subType?: EPathSubType, defaultType: NavigationTreeNodeType = 'directory', ): NavigationTreeNodeType => (subType && pathSubTypeToNodeType[subType]) || pathTypeToNodeType[type] || defaultType; // ==================== const pathSubTypeToEntityName: Record = { [EPathSubType.EPathSubTypeSyncIndexImplTable]: i18n('value_secondary-index-table'), [EPathSubType.EPathSubTypeAsyncIndexImplTable]: i18n('value_secondary-index-table'), [EPathSubType.EPathSubTypeVectorKmeansTreeIndexImplTable]: i18n('value_vector-index-table'), [EPathSubType.EPathSubTypeFulltextIndexImplTable]: i18n('value_fulltext-index-table'), [EPathSubType.EPathSubTypeLocalMinMaxIndex]: undefined, [EPathSubType.EPathSubTypeStreamImpl]: undefined, [EPathSubType.EPathSubTypeEmpty]: undefined, }; const pathTypeToEntityName: Record = { [EPathType.EPathTypeInvalid]: undefined, [EPathType.EPathTypeSubDomain]: i18n('value_database'), [EPathType.EPathTypeExtSubDomain]: i18n('value_database'), [EPathType.EPathTypeDir]: i18n('value_directory'), [EPathType.EPathTypeTable]: i18n('value_table'), [EPathType.EPathTypeSysView]: i18n('value_system-view'), [EPathType.EPathTypeTableIndex]: i18n('value_secondary-index'), [EPathType.EPathTypeColumnStore]: i18n('value_tablestore'), [EPathType.EPathTypeColumnTable]: i18n('value_column-oriented-table'), [EPathType.EPathTypeCdcStream]: i18n('value_changefeed'), [EPathType.EPathTypePersQueueGroup]: i18n('value_topic'), [EPathType.EPathTypeExternalDataSource]: i18n('value_external-data-source'), [EPathType.EPathTypeExternalTable]: i18n('value_external-table'), [EPathType.EPathTypeStreamingQuery]: i18n('value_streaming-query'), [EPathType.EPathTypeView]: i18n('value_view'), [EPathType.EPathTypeReplication]: i18n('value_async-replication'), [EPathType.EPathTypeTransfer]: i18n('value_transfer'), [EPathType.EPathTypeResourcePool]: i18n('value_resource-pool'), [EPathType.EPathTypeSecret]: i18n('value_secret'), }; export const mapPathTypeToEntityName = ( type?: EPathType, subType?: EPathSubType, ): string | undefined => (subType && pathSubTypeToEntityName[subType]) || (type && pathTypeToEntityName[type]); // ==================== const indexTypeToEntityName: Record = { [EIndexType.EIndexTypeInvalid]: undefined, [EIndexType.EIndexTypeGlobal]: i18n('value_secondary-index'), [EIndexType.EIndexTypeGlobalAsync]: i18n('value_secondary-index'), [EIndexType.EIndexTypeGlobalUnique]: i18n('value_secondary-index'), [EIndexType.EIndexTypeGlobalVectorKmeansTree]: i18n('value_vector-index'), [EIndexType.EIndexTypeGlobalFulltext]: i18n('value_fulltext-index'), [EIndexType.EIndexTypeGlobalFulltextPlain]: i18n('value_fulltext-index'), [EIndexType.EIndexTypeGlobalFulltextRelevance]: i18n('value_fulltext-index'), [EIndexType.EIndexTypeLocalBloomFilter]: i18n('value_secondary-index'), [EIndexType.EIndexTypeLocalBloomNgramFilter]: i18n('value_secondary-index'), [EIndexType.EIndexTypeLocalMinMax]: i18n('value_secondary-index'), }; export const mapIndexTypeToEntityName = (type?: EIndexType) => type && indexTypeToEntityName[type]; // ==================== const databaseTypeToDBName: Record = { UnknownTenantType: 'Database', Domain: 'Cluster Root', Dedicated: 'Dedicated Database', Shared: 'Shared Database', Serverless: 'Serverless Database', }; export const mapDatabaseTypeToDBName = (type?: ETenantType) => type && databaseTypeToDBName[type]; // ==================== const pathTypeToIsTable: Record = { [EPathType.EPathTypeTable]: true, [EPathType.EPathTypeColumnTable]: true, [EPathType.EPathTypeSysView]: true, [EPathType.EPathTypeExternalTable]: true, [EPathType.EPathTypeView]: true, [EPathType.EPathTypeInvalid]: false, [EPathType.EPathTypeDir]: false, [EPathType.EPathTypeSubDomain]: false, [EPathType.EPathTypeTableIndex]: false, [EPathType.EPathTypeExtSubDomain]: false, [EPathType.EPathTypeColumnStore]: false, [EPathType.EPathTypeCdcStream]: false, [EPathType.EPathTypePersQueueGroup]: false, [EPathType.EPathTypeExternalDataSource]: false, [EPathType.EPathTypeReplication]: false, [EPathType.EPathTypeTransfer]: false, [EPathType.EPathTypeResourcePool]: false, [EPathType.EPathTypeSecret]: false, [EPathType.EPathTypeStreamingQuery]: false, }; //if add entity with tableType, make sure that Schema is available in Diagnostics section export const isTableType = (pathType?: EPathType) => (pathType && pathTypeToIsTable[pathType]) ?? false; // ==================== const pathTypeToIsColumn: Record = { [EPathType.EPathTypeColumnStore]: true, [EPathType.EPathTypeColumnTable]: true, [EPathType.EPathTypeInvalid]: false, [EPathType.EPathTypeDir]: false, [EPathType.EPathTypeTable]: false, [EPathType.EPathTypeSysView]: false, [EPathType.EPathTypeSubDomain]: false, [EPathType.EPathTypeTableIndex]: false, [EPathType.EPathTypeExtSubDomain]: false, [EPathType.EPathTypeCdcStream]: false, [EPathType.EPathTypePersQueueGroup]: false, [EPathType.EPathTypeExternalDataSource]: false, [EPathType.EPathTypeExternalTable]: false, [EPathType.EPathTypeStreamingQuery]: false, [EPathType.EPathTypeView]: false, [EPathType.EPathTypeReplication]: false, [EPathType.EPathTypeTransfer]: false, [EPathType.EPathTypeResourcePool]: false, [EPathType.EPathTypeSecret]: false, }; export const isColumnEntityType = (type?: EPathType) => (type && pathTypeToIsColumn[type]) ?? false; // ==================== const pathTypeToIsDatabase: Record = { [EPathType.EPathTypeSubDomain]: true, [EPathType.EPathTypeExtSubDomain]: true, [EPathType.EPathTypeInvalid]: false, [EPathType.EPathTypeDir]: false, [EPathType.EPathTypeColumnStore]: false, [EPathType.EPathTypeColumnTable]: false, [EPathType.EPathTypeTable]: false, [EPathType.EPathTypeSysView]: false, [EPathType.EPathTypeTableIndex]: false, [EPathType.EPathTypeCdcStream]: false, [EPathType.EPathTypePersQueueGroup]: false, [EPathType.EPathTypeExternalDataSource]: false, [EPathType.EPathTypeExternalTable]: false, [EPathType.EPathTypeStreamingQuery]: false, [EPathType.EPathTypeView]: false, [EPathType.EPathTypeReplication]: false, [EPathType.EPathTypeTransfer]: false, [EPathType.EPathTypeResourcePool]: false, [EPathType.EPathTypeSecret]: false, }; export const isDatabaseEntityType = (type?: EPathType) => (type && pathTypeToIsDatabase[type]) ?? false; // ==================== export const isCdcStreamEntityType = (type?: EPathType) => type === EPathType.EPathTypeCdcStream; export const isTopicEntityType = (type?: EPathType) => type === EPathType.EPathTypePersQueueGroup; export const isEntityWithTopicData = (type?: EPathType) => type === EPathType.EPathTypeCdcStream || type === EPathType.EPathTypePersQueueGroup; // ==================== const pathSubTypeToChildless: Record = { [EPathSubType.EPathSubTypeSyncIndexImplTable]: true, [EPathSubType.EPathSubTypeAsyncIndexImplTable]: true, [EPathSubType.EPathSubTypeVectorKmeansTreeIndexImplTable]: true, [EPathSubType.EPathSubTypeFulltextIndexImplTable]: true, [EPathSubType.EPathSubTypeStreamImpl]: true, [EPathSubType.EPathSubTypeLocalMinMaxIndex]: true, [EPathSubType.EPathSubTypeEmpty]: false, }; const pathTypeToChildless: Record = { [EPathType.EPathTypeCdcStream]: false, [EPathType.EPathTypePersQueueGroup]: true, [EPathType.EPathTypeExternalDataSource]: true, [EPathType.EPathTypeExternalTable]: true, [EPathType.EPathTypeView]: true, [EPathType.EPathTypeResourcePool]: true, [EPathType.EPathTypeSecret]: true, [EPathType.EPathTypeReplication]: true, [EPathType.EPathTypeTransfer]: true, [EPathType.EPathTypeInvalid]: false, [EPathType.EPathTypeColumnStore]: false, [EPathType.EPathTypeColumnTable]: false, [EPathType.EPathTypeDir]: false, [EPathType.EPathTypeTable]: false, [EPathType.EPathTypeSysView]: false, [EPathType.EPathTypeSubDomain]: false, [EPathType.EPathTypeTableIndex]: false, [EPathType.EPathTypeExtSubDomain]: false, [EPathType.EPathTypeStreamingQuery]: true, }; export const isChildlessPathType = (type?: EPathType, subType?: EPathSubType) => ((subType && pathSubTypeToChildless[subType]) || (type && pathTypeToChildless[type])) ?? false; // ==================== export const isExternalTableType = (type?: EPathType) => type === EPathType.EPathTypeExternalTable; export const isRowTableType = (type?: EPathType) => type === EPathType.EPathTypeTable; export const isViewType = (type?: EPathType) => type === EPathType.EPathTypeView; export const isSystemViewType = (type?: EPathType) => type === EPathType.EPathTypeSysView;