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_INTEGRATION_TYPE ,
10- IntegrationStatus ,
11- IntegrationType ,
12- IntegrationWithStatus ,
13- RawIntegrationType
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,20 +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 : IntegrationType | 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_INTEGRATION_TYPE ) {
174- // Map the Deepnote integration type to our IntegrationType
175- integrationType = DEEPNOTE_TO_INTEGRATION_TYPE [ projectIntegration . type as RawIntegrationType ] ;
176- } else {
177- logger . warn (
178- `IntegrationManager: Unknown integration type '${ projectIntegration . type } ' for integration ID '${ selectedIntegrationId } ' in project '${ projectId } '. Integration type will be undefined.`
179- ) ;
180- }
161+ integrationType = projectIntegration . type as DatabaseIntegrationType ;
181162 }
182163
183164 integrations . set ( selectedIntegrationId , {
@@ -196,35 +177,4 @@ export class IntegrationManager implements IIntegrationManager {
196177 // Show the webview with optional selected integration
197178 await this . webviewProvider . show ( projectId , integrations , selectedIntegrationId ) ;
198179 }
199-
200- /**
201- * Detect integrations by scanning cells directly (fallback method)
202- * This is used when the project isn't stored in the notebook manager
203- */
204- private async detectIntegrationsFromCells ( notebook : NotebookDocument ) : Promise < Map < string , IntegrationWithStatus > > {
205- // Collect all cells with SQL integration metadata
206- const blocksWithIntegrations : BlockWithIntegration [ ] = [ ] ;
207-
208- for ( const cell of notebook . getCells ( ) ) {
209- const metadata = cell . metadata ;
210- logger . trace ( `IntegrationManager: Cell ${ cell . index } metadata:` , metadata ) ;
211-
212- // Check cell metadata for sql_integration_id
213- if ( metadata && typeof metadata === 'object' ) {
214- const integrationId = ( metadata as Record < string , unknown > ) . sql_integration_id ;
215- if ( typeof integrationId === 'string' ) {
216- logger . debug ( `IntegrationManager: Found integration ${ integrationId } in cell ${ cell . index } ` ) ;
217- blocksWithIntegrations . push ( {
218- id : `cell-${ cell . index } ` ,
219- sql_integration_id : integrationId
220- } ) ;
221- }
222- }
223- }
224-
225- logger . debug ( `IntegrationManager: Found ${ blocksWithIntegrations . length } cells with integrations` ) ;
226-
227- // Use the shared utility to scan blocks and build the status map
228- return scanBlocksForIntegrations ( blocksWithIntegrations , this . integrationStorage , 'IntegrationManager' ) ;
229- }
230180}
0 commit comments