* Check for SQL blocks using integrations that aren't configured.
(blocks: DeepnoteBlock[], blockMap: Map<string, BlockInfo>)
| 507 | * Check for SQL blocks using integrations that aren't configured. |
| 508 | */ |
| 509 | function checkMissingIntegrations(blocks: DeepnoteBlock[], blockMap: Map<string, BlockInfo>): IntegrationCheckResult { |
| 510 | const issues: LintIssue[] = [] |
| 511 | const configuredIntegrations = new Set<string>() |
| 512 | const missingIntegrations = new Set<string>() |
| 513 | const integrationUsage = new Map<string, { blockId: string; info: BlockInfo }[]>() |
| 514 | |
| 515 | for (const block of blocks) { |
| 516 | if (block.type !== 'sql') continue |
| 517 | |
| 518 | const metadata = block.metadata as Record<string, unknown> |
| 519 | const integrationId = metadata.sql_integration_id as string | undefined |
| 520 | |
| 521 | if (!integrationId || BUILTIN_INTEGRATIONS.has(integrationId)) { |
| 522 | continue |
| 523 | } |
| 524 | |
| 525 | const info = blockMap.get(block.id) |
| 526 | if (!info) continue |
| 527 | |
| 528 | const envVarName = getSqlEnvVarName(integrationId) |
| 529 | const isConfigured = !!process.env[envVarName] |
| 530 | |
| 531 | if (isConfigured) { |
| 532 | configuredIntegrations.add(integrationId) |
| 533 | } else { |
| 534 | missingIntegrations.add(integrationId) |
| 535 | const usage = integrationUsage.get(integrationId) ?? [] |
| 536 | usage.push({ blockId: block.id, info }) |
| 537 | integrationUsage.set(integrationId, usage) |
| 538 | } |
| 539 | } |
| 540 | |
| 541 | for (const [integrationId, usages] of integrationUsage) { |
| 542 | const envVarName = getSqlEnvVarName(integrationId) |
| 543 | |
| 544 | for (const { blockId, info } of usages) { |
| 545 | issues.push({ |
| 546 | severity: 'error', |
| 547 | code: 'missing-integration', |
| 548 | message: `SQL integration "${integrationId}" is not configured (set ${envVarName})`, |
| 549 | blockId, |
| 550 | blockLabel: info.label, |
| 551 | notebookName: info.notebookName, |
| 552 | details: { integrationId, envVar: envVarName }, |
| 553 | }) |
| 554 | } |
| 555 | } |
| 556 | |
| 557 | return { |
| 558 | issues, |
| 559 | summary: { |
| 560 | configured: Array.from(configuredIntegrations).sort(), |
| 561 | missing: Array.from(missingIntegrations).sort(), |
| 562 | }, |
| 563 | } |
| 564 | } |
| 565 | |
| 566 | interface InputCheckResult { |
no test coverage detected