11import { inject , injectable } from 'inversify' ;
2- import { commands , l10n , NotebookDocument , window , workspace } from 'vscode' ;
2+ import { commands , l10n , window , workspace } from 'vscode' ;
33
44import { IExtensionContext } from '../../../platform/common/types' ;
55import { Commands } from '../../../platform/common/constants' ;
66import { logger } from '../../../platform/logging' ;
77import { IIntegrationDetector , IIntegrationManager , IIntegrationStorage , IIntegrationWebviewProvider } from './types' ;
8- import {
9- DEEPNOTE_TO_LEGACY_INTEGRATION_TYPE ,
10- IntegrationStatus ,
11- LegacyIntegrationType ,
12- IntegrationWithStatus ,
13- RawLegacyIntegrationType
14- } from '../../../platform/notebooks/deepnote/integrationTypes' ;
15- import { BlockWithIntegration , scanBlocksForIntegrations } from './integrationUtils' ;
8+ import { IntegrationStatus } from '../../../platform/notebooks/deepnote/integrationTypes' ;
169import { IDeepnoteNotebookManager } from '../../types' ;
10+ import { DatabaseIntegrationType , databaseIntegrationTypes } from '@deepnote/database-integrations' ;
1711
1812/**
1913 * Manages integration UI and commands for Deepnote notebooks
@@ -143,14 +137,6 @@ export class IntegrationManager implements IIntegrationManager {
143137
144138 // First try to detect integrations from the stored project
145139 let integrations = await this . integrationDetector . detectIntegrations ( projectId ) ;
146-
147- // If no integrations found in stored project, scan cells directly
148- // This handles the case where the notebook was already open when the extension loaded
149- if ( integrations . size === 0 ) {
150- logger . debug ( `IntegrationManager: No integrations found in stored project, scanning cells directly` ) ;
151- integrations = await this . detectIntegrationsFromCells ( activeNotebook ) ;
152- }
153-
154140 logger . debug ( `IntegrationManager: Found ${ integrations . size } integrations` ) ;
155141
156142 // If a specific integration was requested (e.g., from status bar click),
@@ -164,21 +150,15 @@ export class IntegrationManager implements IIntegrationManager {
164150 const projectIntegration = project ?. project . integrations ?. find ( ( i ) => i . id === selectedIntegrationId ) ;
165151
166152 let integrationName : string | undefined ;
167- let integrationType : LegacyIntegrationType | undefined ;
153+ let integrationType : DatabaseIntegrationType | undefined ;
168154
169- if ( projectIntegration ) {
155+ // Validate that projectIntegration.type against supported types
156+ if (
157+ projectIntegration &&
158+ ( databaseIntegrationTypes as readonly string [ ] ) . includes ( projectIntegration . type )
159+ ) {
170160 integrationName = projectIntegration . name ;
171-
172- // Validate that projectIntegration.type exists in the mapping before lookup
173- if ( projectIntegration . type in DEEPNOTE_TO_LEGACY_INTEGRATION_TYPE ) {
174- // Map the Deepnote integration type to our IntegrationType
175- integrationType =
176- DEEPNOTE_TO_LEGACY_INTEGRATION_TYPE [ projectIntegration . type as RawLegacyIntegrationType ] ;
177- } else {
178- logger . warn (
179- `IntegrationManager: Unknown integration type '${ projectIntegration . type } ' for integration ID '${ selectedIntegrationId } ' in project '${ projectId } '. Integration type will be undefined.`
180- ) ;
181- }
161+ integrationType = projectIntegration . type as DatabaseIntegrationType ;
182162 }
183163
184164 integrations . set ( selectedIntegrationId , {
@@ -197,35 +177,4 @@ export class IntegrationManager implements IIntegrationManager {
197177 // Show the webview with optional selected integration
198178 await this . webviewProvider . show ( projectId , integrations , selectedIntegrationId ) ;
199179 }
200-
201- /**
202- * Detect integrations by scanning cells directly (fallback method)
203- * This is used when the project isn't stored in the notebook manager
204- */
205- private async detectIntegrationsFromCells ( notebook : NotebookDocument ) : Promise < Map < string , IntegrationWithStatus > > {
206- // Collect all cells with SQL integration metadata
207- const blocksWithIntegrations : BlockWithIntegration [ ] = [ ] ;
208-
209- for ( const cell of notebook . getCells ( ) ) {
210- const metadata = cell . metadata ;
211- logger . trace ( `IntegrationManager: Cell ${ cell . index } metadata:` , metadata ) ;
212-
213- // Check cell metadata for sql_integration_id
214- if ( metadata && typeof metadata === 'object' ) {
215- const integrationId = ( metadata as Record < string , unknown > ) . sql_integration_id ;
216- if ( typeof integrationId === 'string' ) {
217- logger . debug ( `IntegrationManager: Found integration ${ integrationId } in cell ${ cell . index } ` ) ;
218- blocksWithIntegrations . push ( {
219- id : `cell-${ cell . index } ` ,
220- sql_integration_id : integrationId
221- } ) ;
222- }
223- }
224- }
225-
226- logger . debug ( `IntegrationManager: Found ${ blocksWithIntegrations . length } cells with integrations` ) ;
227-
228- // Use the shared utility to scan blocks and build the status map
229- return scanBlocksForIntegrations ( blocksWithIntegrations , this . integrationStorage , 'IntegrationManager' ) ;
230- }
231180}
0 commit comments