@useatlas/create 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +231 -0
- package/index.ts +829 -0
- package/package.json +38 -0
- package/templates/docker/.env.example +67 -0
- package/templates/docker/Dockerfile +52 -0
- package/templates/docker/bin/__tests__/benchmark.test.ts +598 -0
- package/templates/docker/bin/__tests__/duckdb-ingest.test.ts +171 -0
- package/templates/docker/bin/__tests__/eval.test.ts +434 -0
- package/templates/docker/bin/__tests__/matview-partition.test.ts +615 -0
- package/templates/docker/bin/__tests__/multi-source.test.ts +113 -0
- package/templates/docker/bin/__tests__/plugin-cli.test.ts +322 -0
- package/templates/docker/bin/__tests__/profiler-heuristics.test.ts +608 -0
- package/templates/docker/bin/__tests__/query.test.ts +240 -0
- package/templates/docker/bin/__tests__/schema-drift.test.ts +542 -0
- package/templates/docker/bin/__tests__/view-yaml-generation.test.ts +146 -0
- package/templates/docker/bin/atlas.ts +5044 -0
- package/templates/docker/bin/benchmark.ts +695 -0
- package/templates/docker/bin/enrich.ts +559 -0
- package/templates/docker/bin/eval.ts +770 -0
- package/templates/docker/bin/smoke.ts +438 -0
- package/templates/docker/data/.gitkeep +0 -0
- package/templates/docker/data/cybersec.sql +1961 -0
- package/templates/docker/data/demo-semantic/catalog.yml +40 -0
- package/templates/docker/data/demo-semantic/entities/accounts.yml +170 -0
- package/templates/docker/data/demo-semantic/entities/companies.yml +207 -0
- package/templates/docker/data/demo-semantic/entities/people.yml +145 -0
- package/templates/docker/data/demo-semantic/glossary.yml +22 -0
- package/templates/docker/data/demo-semantic/metrics/accounts.yml +38 -0
- package/templates/docker/data/demo-semantic/metrics/companies.yml +89 -0
- package/templates/docker/data/demo.sql +373 -0
- package/templates/docker/data/ecommerce.sql +1690 -0
- package/templates/docker/data/init-demo-db.sql +8 -0
- package/templates/docker/docker-compose.yml +34 -0
- package/templates/docker/docs/deploy.md +390 -0
- package/templates/docker/eslint.config.mjs +18 -0
- package/templates/docker/gitignore +5 -0
- package/templates/docker/next.config.ts +9 -0
- package/templates/docker/package.json +59 -0
- package/templates/docker/postcss.config.mjs +8 -0
- package/templates/docker/public/.gitkeep +0 -0
- package/templates/docker/public/favicon.svg +4 -0
- package/templates/docker/railway.json +13 -0
- package/templates/docker/render.yaml +34 -0
- package/templates/docker/semantic/catalog.yml +5 -0
- package/templates/docker/semantic/entities/.gitkeep +0 -0
- package/templates/docker/semantic/glossary.yml +6 -0
- package/templates/docker/semantic/metrics/.gitkeep +0 -0
- package/templates/docker/sidecar/Dockerfile +28 -0
- package/templates/docker/sidecar/railway.json +14 -0
- package/templates/docker/sidecar/server.ts +188 -0
- package/templates/docker/src/api/__tests__/actions.test.ts +683 -0
- package/templates/docker/src/api/__tests__/admin.test.ts +820 -0
- package/templates/docker/src/api/__tests__/auth.test.ts +165 -0
- package/templates/docker/src/api/__tests__/chat.test.ts +376 -0
- package/templates/docker/src/api/__tests__/conversations.test.ts +555 -0
- package/templates/docker/src/api/__tests__/cors.test.ts +135 -0
- package/templates/docker/src/api/__tests__/health-plugin.test.ts +169 -0
- package/templates/docker/src/api/__tests__/health.test.ts +261 -0
- package/templates/docker/src/api/__tests__/query.test.ts +891 -0
- package/templates/docker/src/api/__tests__/scheduled-tasks.test.ts +601 -0
- package/templates/docker/src/api/__tests__/slack.test.ts +847 -0
- package/templates/docker/src/api/index.ts +117 -0
- package/templates/docker/src/api/routes/actions.ts +274 -0
- package/templates/docker/src/api/routes/admin.ts +757 -0
- package/templates/docker/src/api/routes/auth.ts +48 -0
- package/templates/docker/src/api/routes/chat.ts +465 -0
- package/templates/docker/src/api/routes/conversations.ts +266 -0
- package/templates/docker/src/api/routes/health.ts +287 -0
- package/templates/docker/src/api/routes/openapi.ts +390 -0
- package/templates/docker/src/api/routes/query.ts +318 -0
- package/templates/docker/src/api/routes/scheduled-tasks.ts +467 -0
- package/templates/docker/src/api/routes/slack.ts +611 -0
- package/templates/docker/src/api/server.ts +226 -0
- package/templates/docker/src/app/api/[...route]/route.ts +33 -0
- package/templates/docker/src/app/error.tsx +24 -0
- package/templates/docker/src/app/globals.css +126 -0
- package/templates/docker/src/app/layout.tsx +19 -0
- package/templates/docker/src/app/page.tsx +14 -0
- package/templates/docker/src/global.d.ts +1 -0
- package/templates/docker/src/lib/__tests__/agent-cache.test.ts +437 -0
- package/templates/docker/src/lib/__tests__/agent-dialect.test.ts +114 -0
- package/templates/docker/src/lib/__tests__/agent-health-annotations.test.ts +164 -0
- package/templates/docker/src/lib/__tests__/agent-integration.test.ts +514 -0
- package/templates/docker/src/lib/__tests__/config-actions.test.ts +166 -0
- package/templates/docker/src/lib/__tests__/config.test.ts +1063 -0
- package/templates/docker/src/lib/__tests__/conversations.test.ts +589 -0
- package/templates/docker/src/lib/__tests__/errors.test.ts +256 -0
- package/templates/docker/src/lib/__tests__/logger.test.ts +200 -0
- package/templates/docker/src/lib/__tests__/providers.test.ts +99 -0
- package/templates/docker/src/lib/__tests__/rls.test.ts +435 -0
- package/templates/docker/src/lib/__tests__/scheduled-task-types.test.ts +124 -0
- package/templates/docker/src/lib/__tests__/scheduled-tasks.test.ts +550 -0
- package/templates/docker/src/lib/__tests__/semantic-index.test.ts +547 -0
- package/templates/docker/src/lib/__tests__/semantic-multisource.test.ts +544 -0
- package/templates/docker/src/lib/__tests__/semantic.test.ts +363 -0
- package/templates/docker/src/lib/__tests__/startup-actions.test.ts +452 -0
- package/templates/docker/src/lib/__tests__/startup.test.ts +465 -0
- package/templates/docker/src/lib/__tests__/tracing.test.ts +28 -0
- package/templates/docker/src/lib/action-types.ts +95 -0
- package/templates/docker/src/lib/agent-query.ts +178 -0
- package/templates/docker/src/lib/agent.ts +505 -0
- package/templates/docker/src/lib/api-url.ts +2 -0
- package/templates/docker/src/lib/auth/__tests__/audit.test.ts +418 -0
- package/templates/docker/src/lib/auth/__tests__/byot-integration.test.ts +222 -0
- package/templates/docker/src/lib/auth/__tests__/byot.test.ts +366 -0
- package/templates/docker/src/lib/auth/__tests__/detect.test.ts +190 -0
- package/templates/docker/src/lib/auth/__tests__/managed.test.ts +173 -0
- package/templates/docker/src/lib/auth/__tests__/middleware.test.ts +456 -0
- package/templates/docker/src/lib/auth/__tests__/migrate.test.ts +201 -0
- package/templates/docker/src/lib/auth/__tests__/permissions.test.ts +225 -0
- package/templates/docker/src/lib/auth/__tests__/server.test.ts +34 -0
- package/templates/docker/src/lib/auth/__tests__/simple-key.test.ts +176 -0
- package/templates/docker/src/lib/auth/__tests__/types.test.ts +44 -0
- package/templates/docker/src/lib/auth/audit.ts +89 -0
- package/templates/docker/src/lib/auth/byot.ts +158 -0
- package/templates/docker/src/lib/auth/client.ts +35 -0
- package/templates/docker/src/lib/auth/detect.ts +83 -0
- package/templates/docker/src/lib/auth/managed.ts +73 -0
- package/templates/docker/src/lib/auth/middleware.ts +208 -0
- package/templates/docker/src/lib/auth/migrate.ts +111 -0
- package/templates/docker/src/lib/auth/permissions.ts +156 -0
- package/templates/docker/src/lib/auth/server.ts +142 -0
- package/templates/docker/src/lib/auth/simple-key.ts +92 -0
- package/templates/docker/src/lib/auth/types.ts +49 -0
- package/templates/docker/src/lib/config.ts +704 -0
- package/templates/docker/src/lib/conversation-types.ts +29 -0
- package/templates/docker/src/lib/conversations.ts +270 -0
- package/templates/docker/src/lib/db/__tests__/connection.test.ts +69 -0
- package/templates/docker/src/lib/db/__tests__/duckdb.test.ts +141 -0
- package/templates/docker/src/lib/db/__tests__/internal.test.ts +387 -0
- package/templates/docker/src/lib/db/__tests__/registry-health.test.ts +207 -0
- package/templates/docker/src/lib/db/__tests__/registry-pool-limits.test.ts +156 -0
- package/templates/docker/src/lib/db/__tests__/registry.test.ts +595 -0
- package/templates/docker/src/lib/db/__tests__/salesforce.test.ts +339 -0
- package/templates/docker/src/lib/db/__tests__/snowflake.test.ts +217 -0
- package/templates/docker/src/lib/db/__tests__/source-rate-limit.test.ts +130 -0
- package/templates/docker/src/lib/db/connection.ts +753 -0
- package/templates/docker/src/lib/db/duckdb.ts +122 -0
- package/templates/docker/src/lib/db/internal.ts +273 -0
- package/templates/docker/src/lib/db/salesforce.ts +342 -0
- package/templates/docker/src/lib/db/source-rate-limit.ts +191 -0
- package/templates/docker/src/lib/errors.ts +154 -0
- package/templates/docker/src/lib/logger.ts +98 -0
- package/templates/docker/src/lib/plugins/__tests__/hooks-integration.test.ts +202 -0
- package/templates/docker/src/lib/plugins/__tests__/hooks.test.ts +529 -0
- package/templates/docker/src/lib/plugins/__tests__/migrate.test.ts +521 -0
- package/templates/docker/src/lib/plugins/__tests__/registry.test.ts +346 -0
- package/templates/docker/src/lib/plugins/__tests__/tools.test.ts +49 -0
- package/templates/docker/src/lib/plugins/__tests__/wiring.test.ts +585 -0
- package/templates/docker/src/lib/plugins/hooks.ts +162 -0
- package/templates/docker/src/lib/plugins/index.ts +9 -0
- package/templates/docker/src/lib/plugins/migrate.ts +309 -0
- package/templates/docker/src/lib/plugins/registry.ts +231 -0
- package/templates/docker/src/lib/plugins/tools.ts +39 -0
- package/templates/docker/src/lib/plugins/wiring.ts +291 -0
- package/templates/docker/src/lib/providers.ts +102 -0
- package/templates/docker/src/lib/rls.ts +321 -0
- package/templates/docker/src/lib/scheduled-task-types.ts +132 -0
- package/templates/docker/src/lib/scheduled-tasks.ts +475 -0
- package/templates/docker/src/lib/scheduler/__tests__/delivery.test.ts +192 -0
- package/templates/docker/src/lib/scheduler/__tests__/engine.test.ts +248 -0
- package/templates/docker/src/lib/scheduler/__tests__/format-email.test.ts +96 -0
- package/templates/docker/src/lib/scheduler/__tests__/format-slack.test.ts +78 -0
- package/templates/docker/src/lib/scheduler/__tests__/format-webhook.test.ts +78 -0
- package/templates/docker/src/lib/scheduler/delivery.ts +248 -0
- package/templates/docker/src/lib/scheduler/engine.ts +317 -0
- package/templates/docker/src/lib/scheduler/executor.ts +73 -0
- package/templates/docker/src/lib/scheduler/format-email.ts +109 -0
- package/templates/docker/src/lib/scheduler/format-slack.ts +35 -0
- package/templates/docker/src/lib/scheduler/format-webhook.ts +37 -0
- package/templates/docker/src/lib/scheduler/index.ts +7 -0
- package/templates/docker/src/lib/security.ts +11 -0
- package/templates/docker/src/lib/semantic-index.ts +503 -0
- package/templates/docker/src/lib/semantic.ts +387 -0
- package/templates/docker/src/lib/sidecar-types.ts +16 -0
- package/templates/docker/src/lib/slack/__tests__/api.test.ts +160 -0
- package/templates/docker/src/lib/slack/__tests__/format.test.ts +237 -0
- package/templates/docker/src/lib/slack/__tests__/store.test.ts +188 -0
- package/templates/docker/src/lib/slack/__tests__/threads.test.ts +112 -0
- package/templates/docker/src/lib/slack/__tests__/verify.test.ts +111 -0
- package/templates/docker/src/lib/slack/api.ts +102 -0
- package/templates/docker/src/lib/slack/format.ts +209 -0
- package/templates/docker/src/lib/slack/store.ts +107 -0
- package/templates/docker/src/lib/slack/threads.ts +64 -0
- package/templates/docker/src/lib/slack/verify.ts +71 -0
- package/templates/docker/src/lib/startup.ts +730 -0
- package/templates/docker/src/lib/tools/__tests__/action-permissions.test.ts +594 -0
- package/templates/docker/src/lib/tools/__tests__/custom-validation.test.ts +238 -0
- package/templates/docker/src/lib/tools/__tests__/explore-backend.test.ts +267 -0
- package/templates/docker/src/lib/tools/__tests__/explore-nsjail.test.ts +492 -0
- package/templates/docker/src/lib/tools/__tests__/explore-plugin.test.ts +374 -0
- package/templates/docker/src/lib/tools/__tests__/explore-sdk-compat.test.ts +82 -0
- package/templates/docker/src/lib/tools/__tests__/explore-sidecar.test.ts +208 -0
- package/templates/docker/src/lib/tools/__tests__/registry-actions.test.ts +144 -0
- package/templates/docker/src/lib/tools/__tests__/registry.test.ts +235 -0
- package/templates/docker/src/lib/tools/__tests__/salesforce-tool.test.ts +154 -0
- package/templates/docker/src/lib/tools/__tests__/soql-validation.test.ts +303 -0
- package/templates/docker/src/lib/tools/__tests__/sql-audit.test.ts +225 -0
- package/templates/docker/src/lib/tools/__tests__/sql-connection-whitelist.test.ts +98 -0
- package/templates/docker/src/lib/tools/__tests__/sql-duckdb.test.ts +233 -0
- package/templates/docker/src/lib/tools/__tests__/sql-ratelimit.test.ts +225 -0
- package/templates/docker/src/lib/tools/__tests__/sql.test.ts +1012 -0
- package/templates/docker/src/lib/tools/actions/__tests__/audit.test.ts +211 -0
- package/templates/docker/src/lib/tools/actions/__tests__/email.test.ts +378 -0
- package/templates/docker/src/lib/tools/actions/__tests__/handler.test.ts +681 -0
- package/templates/docker/src/lib/tools/actions/__tests__/jira.test.ts +427 -0
- package/templates/docker/src/lib/tools/actions/audit.ts +47 -0
- package/templates/docker/src/lib/tools/actions/email.ts +191 -0
- package/templates/docker/src/lib/tools/actions/handler.ts +591 -0
- package/templates/docker/src/lib/tools/actions/index.ts +23 -0
- package/templates/docker/src/lib/tools/actions/jira.ts +220 -0
- package/templates/docker/src/lib/tools/explore-nsjail.ts +343 -0
- package/templates/docker/src/lib/tools/explore-sandbox.ts +264 -0
- package/templates/docker/src/lib/tools/explore-sidecar.ts +163 -0
- package/templates/docker/src/lib/tools/explore.ts +379 -0
- package/templates/docker/src/lib/tools/registry.ts +221 -0
- package/templates/docker/src/lib/tools/salesforce.ts +138 -0
- package/templates/docker/src/lib/tools/soql-validation.ts +172 -0
- package/templates/docker/src/lib/tools/sql.ts +680 -0
- package/templates/docker/src/lib/tracing.ts +40 -0
- package/templates/docker/src/lib/utils.ts +6 -0
- package/templates/docker/src/test-setup.ts +38 -0
- package/templates/docker/src/types/vercel-sandbox.d.ts +54 -0
- package/templates/docker/src/ui/components/actions/action-approval-card.tsx +295 -0
- package/templates/docker/src/ui/components/actions/action-status-badge.tsx +50 -0
- package/templates/docker/src/ui/components/admin/admin-layout.tsx +26 -0
- package/templates/docker/src/ui/components/admin/admin-sidebar.tsx +96 -0
- package/templates/docker/src/ui/components/admin/empty-state.tsx +24 -0
- package/templates/docker/src/ui/components/admin/entity-detail.tsx +233 -0
- package/templates/docker/src/ui/components/admin/entity-list.tsx +96 -0
- package/templates/docker/src/ui/components/admin/error-banner.tsx +22 -0
- package/templates/docker/src/ui/components/admin/feature-disabled.tsx +44 -0
- package/templates/docker/src/ui/components/admin/health-badge.tsx +30 -0
- package/templates/docker/src/ui/components/admin/loading-state.tsx +14 -0
- package/templates/docker/src/ui/components/admin/stat-card.tsx +32 -0
- package/templates/docker/src/ui/components/atlas-chat.tsx +370 -0
- package/templates/docker/src/ui/components/chart/chart-detection.ts +261 -0
- package/templates/docker/src/ui/components/chart/result-chart.tsx +375 -0
- package/templates/docker/src/ui/components/chat/api-key-bar.tsx +66 -0
- package/templates/docker/src/ui/components/chat/copy-button.tsx +25 -0
- package/templates/docker/src/ui/components/chat/data-table.tsx +102 -0
- package/templates/docker/src/ui/components/chat/error-banner.tsx +32 -0
- package/templates/docker/src/ui/components/chat/explore-card.tsx +41 -0
- package/templates/docker/src/ui/components/chat/loading-card.tsx +10 -0
- package/templates/docker/src/ui/components/chat/managed-auth-card.tsx +116 -0
- package/templates/docker/src/ui/components/chat/markdown.tsx +72 -0
- package/templates/docker/src/ui/components/chat/sql-block.tsx +30 -0
- package/templates/docker/src/ui/components/chat/sql-result-card.tsx +144 -0
- package/templates/docker/src/ui/components/chat/starter-prompts.ts +6 -0
- package/templates/docker/src/ui/components/chat/tool-part.tsx +40 -0
- package/templates/docker/src/ui/components/chat/typing-indicator.tsx +19 -0
- package/templates/docker/src/ui/components/conversations/conversation-item.tsx +120 -0
- package/templates/docker/src/ui/components/conversations/conversation-list.tsx +66 -0
- package/templates/docker/src/ui/components/conversations/conversation-sidebar.tsx +78 -0
- package/templates/docker/src/ui/components/conversations/delete-confirmation.tsx +27 -0
- package/templates/docker/src/ui/context.tsx +78 -0
- package/templates/docker/src/ui/hooks/use-admin-fetch.ts +104 -0
- package/templates/docker/src/ui/hooks/use-conversations.ts +184 -0
- package/templates/docker/src/ui/hooks/use-dark-mode.ts +17 -0
- package/templates/docker/src/ui/lib/action-types.ts +63 -0
- package/templates/docker/src/ui/lib/helpers.ts +104 -0
- package/templates/docker/src/ui/lib/types.ts +145 -0
- package/templates/docker/tsconfig.json +41 -0
- package/templates/docker/vercel.json +3 -0
- package/templates/nextjs-standalone/.env.example +68 -0
- package/templates/nextjs-standalone/bin/__tests__/benchmark.test.ts +598 -0
- package/templates/nextjs-standalone/bin/__tests__/duckdb-ingest.test.ts +171 -0
- package/templates/nextjs-standalone/bin/__tests__/eval.test.ts +434 -0
- package/templates/nextjs-standalone/bin/__tests__/matview-partition.test.ts +615 -0
- package/templates/nextjs-standalone/bin/__tests__/multi-source.test.ts +113 -0
- package/templates/nextjs-standalone/bin/__tests__/plugin-cli.test.ts +322 -0
- package/templates/nextjs-standalone/bin/__tests__/profiler-heuristics.test.ts +608 -0
- package/templates/nextjs-standalone/bin/__tests__/query.test.ts +240 -0
- package/templates/nextjs-standalone/bin/__tests__/schema-drift.test.ts +542 -0
- package/templates/nextjs-standalone/bin/__tests__/view-yaml-generation.test.ts +146 -0
- package/templates/nextjs-standalone/bin/atlas.ts +5044 -0
- package/templates/nextjs-standalone/bin/benchmark.ts +695 -0
- package/templates/nextjs-standalone/bin/enrich.ts +559 -0
- package/templates/nextjs-standalone/bin/eval.ts +770 -0
- package/templates/nextjs-standalone/bin/smoke.ts +438 -0
- package/templates/nextjs-standalone/data/.gitkeep +0 -0
- package/templates/nextjs-standalone/data/cybersec.sql +1961 -0
- package/templates/nextjs-standalone/data/demo-semantic/catalog.yml +40 -0
- package/templates/nextjs-standalone/data/demo-semantic/entities/accounts.yml +170 -0
- package/templates/nextjs-standalone/data/demo-semantic/entities/companies.yml +207 -0
- package/templates/nextjs-standalone/data/demo-semantic/entities/people.yml +145 -0
- package/templates/nextjs-standalone/data/demo-semantic/glossary.yml +22 -0
- package/templates/nextjs-standalone/data/demo-semantic/metrics/accounts.yml +38 -0
- package/templates/nextjs-standalone/data/demo-semantic/metrics/companies.yml +89 -0
- package/templates/nextjs-standalone/data/demo.sql +373 -0
- package/templates/nextjs-standalone/data/ecommerce.sql +1690 -0
- package/templates/nextjs-standalone/data/init-demo-db.sql +8 -0
- package/templates/nextjs-standalone/docs/deploy.md +390 -0
- package/templates/nextjs-standalone/eslint.config.mjs +18 -0
- package/templates/nextjs-standalone/gitignore +5 -0
- package/templates/nextjs-standalone/next.config.ts +10 -0
- package/templates/nextjs-standalone/package.json +63 -0
- package/templates/nextjs-standalone/postcss.config.mjs +8 -0
- package/templates/nextjs-standalone/semantic/catalog.yml +5 -0
- package/templates/nextjs-standalone/semantic/entities/.gitkeep +0 -0
- package/templates/nextjs-standalone/semantic/glossary.yml +6 -0
- package/templates/nextjs-standalone/semantic/metrics/.gitkeep +0 -0
- package/templates/nextjs-standalone/src/api/__tests__/actions.test.ts +683 -0
- package/templates/nextjs-standalone/src/api/__tests__/admin.test.ts +820 -0
- package/templates/nextjs-standalone/src/api/__tests__/auth.test.ts +165 -0
- package/templates/nextjs-standalone/src/api/__tests__/chat.test.ts +376 -0
- package/templates/nextjs-standalone/src/api/__tests__/conversations.test.ts +555 -0
- package/templates/nextjs-standalone/src/api/__tests__/cors.test.ts +135 -0
- package/templates/nextjs-standalone/src/api/__tests__/health-plugin.test.ts +169 -0
- package/templates/nextjs-standalone/src/api/__tests__/health.test.ts +261 -0
- package/templates/nextjs-standalone/src/api/__tests__/query.test.ts +891 -0
- package/templates/nextjs-standalone/src/api/__tests__/scheduled-tasks.test.ts +601 -0
- package/templates/nextjs-standalone/src/api/__tests__/slack.test.ts +847 -0
- package/templates/nextjs-standalone/src/api/index.ts +117 -0
- package/templates/nextjs-standalone/src/api/routes/actions.ts +274 -0
- package/templates/nextjs-standalone/src/api/routes/admin.ts +757 -0
- package/templates/nextjs-standalone/src/api/routes/auth.ts +48 -0
- package/templates/nextjs-standalone/src/api/routes/chat.ts +465 -0
- package/templates/nextjs-standalone/src/api/routes/conversations.ts +266 -0
- package/templates/nextjs-standalone/src/api/routes/health.ts +287 -0
- package/templates/nextjs-standalone/src/api/routes/openapi.ts +390 -0
- package/templates/nextjs-standalone/src/api/routes/query.ts +318 -0
- package/templates/nextjs-standalone/src/api/routes/scheduled-tasks.ts +467 -0
- package/templates/nextjs-standalone/src/api/routes/slack.ts +611 -0
- package/templates/nextjs-standalone/src/api/server.ts +226 -0
- package/templates/nextjs-standalone/src/app/api/[...route]/route.ts +33 -0
- package/templates/nextjs-standalone/src/app/error.tsx +24 -0
- package/templates/nextjs-standalone/src/app/global-error.tsx +68 -0
- package/templates/nextjs-standalone/src/app/globals.css +126 -0
- package/templates/nextjs-standalone/src/app/layout.tsx +19 -0
- package/templates/nextjs-standalone/src/app/page.tsx +14 -0
- package/templates/nextjs-standalone/src/lib/__tests__/agent-cache.test.ts +437 -0
- package/templates/nextjs-standalone/src/lib/__tests__/agent-dialect.test.ts +114 -0
- package/templates/nextjs-standalone/src/lib/__tests__/agent-health-annotations.test.ts +164 -0
- package/templates/nextjs-standalone/src/lib/__tests__/agent-integration.test.ts +514 -0
- package/templates/nextjs-standalone/src/lib/__tests__/config-actions.test.ts +166 -0
- package/templates/nextjs-standalone/src/lib/__tests__/config.test.ts +1063 -0
- package/templates/nextjs-standalone/src/lib/__tests__/conversations.test.ts +589 -0
- package/templates/nextjs-standalone/src/lib/__tests__/errors.test.ts +256 -0
- package/templates/nextjs-standalone/src/lib/__tests__/logger.test.ts +200 -0
- package/templates/nextjs-standalone/src/lib/__tests__/providers.test.ts +99 -0
- package/templates/nextjs-standalone/src/lib/__tests__/rls.test.ts +435 -0
- package/templates/nextjs-standalone/src/lib/__tests__/scheduled-task-types.test.ts +124 -0
- package/templates/nextjs-standalone/src/lib/__tests__/scheduled-tasks.test.ts +550 -0
- package/templates/nextjs-standalone/src/lib/__tests__/semantic-index.test.ts +547 -0
- package/templates/nextjs-standalone/src/lib/__tests__/semantic-multisource.test.ts +544 -0
- package/templates/nextjs-standalone/src/lib/__tests__/semantic.test.ts +363 -0
- package/templates/nextjs-standalone/src/lib/__tests__/startup-actions.test.ts +452 -0
- package/templates/nextjs-standalone/src/lib/__tests__/startup.test.ts +465 -0
- package/templates/nextjs-standalone/src/lib/__tests__/tracing.test.ts +28 -0
- package/templates/nextjs-standalone/src/lib/action-types.ts +95 -0
- package/templates/nextjs-standalone/src/lib/agent-query.ts +178 -0
- package/templates/nextjs-standalone/src/lib/agent.ts +505 -0
- package/templates/nextjs-standalone/src/lib/api-url.ts +3 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/audit.test.ts +418 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/byot-integration.test.ts +222 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/byot.test.ts +366 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/detect.test.ts +190 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/managed.test.ts +173 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/middleware.test.ts +456 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/migrate.test.ts +201 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/permissions.test.ts +225 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/server.test.ts +34 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/simple-key.test.ts +176 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/types.test.ts +44 -0
- package/templates/nextjs-standalone/src/lib/auth/audit.ts +89 -0
- package/templates/nextjs-standalone/src/lib/auth/byot.ts +158 -0
- package/templates/nextjs-standalone/src/lib/auth/client.ts +23 -0
- package/templates/nextjs-standalone/src/lib/auth/detect.ts +83 -0
- package/templates/nextjs-standalone/src/lib/auth/managed.ts +73 -0
- package/templates/nextjs-standalone/src/lib/auth/middleware.ts +208 -0
- package/templates/nextjs-standalone/src/lib/auth/migrate.ts +111 -0
- package/templates/nextjs-standalone/src/lib/auth/permissions.ts +156 -0
- package/templates/nextjs-standalone/src/lib/auth/server.ts +142 -0
- package/templates/nextjs-standalone/src/lib/auth/simple-key.ts +92 -0
- package/templates/nextjs-standalone/src/lib/auth/types.ts +49 -0
- package/templates/nextjs-standalone/src/lib/config.ts +704 -0
- package/templates/nextjs-standalone/src/lib/conversation-types.ts +29 -0
- package/templates/nextjs-standalone/src/lib/conversations.ts +270 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/connection.test.ts +69 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/duckdb.test.ts +141 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/internal.test.ts +387 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/registry-health.test.ts +207 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/registry-pool-limits.test.ts +156 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/registry.test.ts +595 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/salesforce.test.ts +339 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/snowflake.test.ts +217 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/source-rate-limit.test.ts +130 -0
- package/templates/nextjs-standalone/src/lib/db/connection.ts +753 -0
- package/templates/nextjs-standalone/src/lib/db/duckdb.ts +122 -0
- package/templates/nextjs-standalone/src/lib/db/internal.ts +273 -0
- package/templates/nextjs-standalone/src/lib/db/salesforce.ts +342 -0
- package/templates/nextjs-standalone/src/lib/db/source-rate-limit.ts +191 -0
- package/templates/nextjs-standalone/src/lib/errors.ts +154 -0
- package/templates/nextjs-standalone/src/lib/logger.ts +98 -0
- package/templates/nextjs-standalone/src/lib/plugins/__tests__/hooks-integration.test.ts +202 -0
- package/templates/nextjs-standalone/src/lib/plugins/__tests__/hooks.test.ts +529 -0
- package/templates/nextjs-standalone/src/lib/plugins/__tests__/migrate.test.ts +521 -0
- package/templates/nextjs-standalone/src/lib/plugins/__tests__/registry.test.ts +346 -0
- package/templates/nextjs-standalone/src/lib/plugins/__tests__/tools.test.ts +49 -0
- package/templates/nextjs-standalone/src/lib/plugins/__tests__/wiring.test.ts +585 -0
- package/templates/nextjs-standalone/src/lib/plugins/hooks.ts +162 -0
- package/templates/nextjs-standalone/src/lib/plugins/index.ts +9 -0
- package/templates/nextjs-standalone/src/lib/plugins/migrate.ts +309 -0
- package/templates/nextjs-standalone/src/lib/plugins/registry.ts +231 -0
- package/templates/nextjs-standalone/src/lib/plugins/tools.ts +39 -0
- package/templates/nextjs-standalone/src/lib/plugins/wiring.ts +291 -0
- package/templates/nextjs-standalone/src/lib/providers.ts +102 -0
- package/templates/nextjs-standalone/src/lib/rls.ts +321 -0
- package/templates/nextjs-standalone/src/lib/scheduled-task-types.ts +132 -0
- package/templates/nextjs-standalone/src/lib/scheduled-tasks.ts +475 -0
- package/templates/nextjs-standalone/src/lib/scheduler/__tests__/delivery.test.ts +192 -0
- package/templates/nextjs-standalone/src/lib/scheduler/__tests__/engine.test.ts +248 -0
- package/templates/nextjs-standalone/src/lib/scheduler/__tests__/format-email.test.ts +96 -0
- package/templates/nextjs-standalone/src/lib/scheduler/__tests__/format-slack.test.ts +78 -0
- package/templates/nextjs-standalone/src/lib/scheduler/__tests__/format-webhook.test.ts +78 -0
- package/templates/nextjs-standalone/src/lib/scheduler/delivery.ts +248 -0
- package/templates/nextjs-standalone/src/lib/scheduler/engine.ts +317 -0
- package/templates/nextjs-standalone/src/lib/scheduler/executor.ts +73 -0
- package/templates/nextjs-standalone/src/lib/scheduler/format-email.ts +109 -0
- package/templates/nextjs-standalone/src/lib/scheduler/format-slack.ts +35 -0
- package/templates/nextjs-standalone/src/lib/scheduler/format-webhook.ts +37 -0
- package/templates/nextjs-standalone/src/lib/scheduler/index.ts +7 -0
- package/templates/nextjs-standalone/src/lib/security.ts +11 -0
- package/templates/nextjs-standalone/src/lib/semantic-index.ts +503 -0
- package/templates/nextjs-standalone/src/lib/semantic.ts +387 -0
- package/templates/nextjs-standalone/src/lib/sidecar-types.ts +16 -0
- package/templates/nextjs-standalone/src/lib/slack/__tests__/api.test.ts +160 -0
- package/templates/nextjs-standalone/src/lib/slack/__tests__/format.test.ts +237 -0
- package/templates/nextjs-standalone/src/lib/slack/__tests__/store.test.ts +188 -0
- package/templates/nextjs-standalone/src/lib/slack/__tests__/threads.test.ts +112 -0
- package/templates/nextjs-standalone/src/lib/slack/__tests__/verify.test.ts +111 -0
- package/templates/nextjs-standalone/src/lib/slack/api.ts +102 -0
- package/templates/nextjs-standalone/src/lib/slack/format.ts +209 -0
- package/templates/nextjs-standalone/src/lib/slack/store.ts +107 -0
- package/templates/nextjs-standalone/src/lib/slack/threads.ts +64 -0
- package/templates/nextjs-standalone/src/lib/slack/verify.ts +71 -0
- package/templates/nextjs-standalone/src/lib/startup.ts +730 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/action-permissions.test.ts +594 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/custom-validation.test.ts +238 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/explore-backend.test.ts +267 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/explore-nsjail.test.ts +492 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/explore-plugin.test.ts +374 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/explore-sdk-compat.test.ts +82 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/explore-sidecar.test.ts +208 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/registry-actions.test.ts +144 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/registry.test.ts +235 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/salesforce-tool.test.ts +154 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/soql-validation.test.ts +303 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/sql-audit.test.ts +225 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/sql-connection-whitelist.test.ts +98 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/sql-duckdb.test.ts +233 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/sql-ratelimit.test.ts +225 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/sql.test.ts +1012 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/__tests__/audit.test.ts +211 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/__tests__/email.test.ts +378 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/__tests__/handler.test.ts +681 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/__tests__/jira.test.ts +427 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/audit.ts +47 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/email.ts +191 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/handler.ts +591 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/index.ts +23 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/jira.ts +220 -0
- package/templates/nextjs-standalone/src/lib/tools/explore-nsjail.ts +343 -0
- package/templates/nextjs-standalone/src/lib/tools/explore-sandbox.ts +264 -0
- package/templates/nextjs-standalone/src/lib/tools/explore-sidecar.ts +163 -0
- package/templates/nextjs-standalone/src/lib/tools/explore.ts +379 -0
- package/templates/nextjs-standalone/src/lib/tools/registry.ts +221 -0
- package/templates/nextjs-standalone/src/lib/tools/salesforce.ts +138 -0
- package/templates/nextjs-standalone/src/lib/tools/soql-validation.ts +172 -0
- package/templates/nextjs-standalone/src/lib/tools/sql.ts +680 -0
- package/templates/nextjs-standalone/src/lib/tracing.ts +40 -0
- package/templates/nextjs-standalone/src/lib/utils.ts +6 -0
- package/templates/nextjs-standalone/src/test-setup.ts +38 -0
- package/templates/nextjs-standalone/src/ui/components/actions/action-approval-card.tsx +295 -0
- package/templates/nextjs-standalone/src/ui/components/actions/action-status-badge.tsx +50 -0
- package/templates/nextjs-standalone/src/ui/components/admin/admin-layout.tsx +26 -0
- package/templates/nextjs-standalone/src/ui/components/admin/admin-sidebar.tsx +96 -0
- package/templates/nextjs-standalone/src/ui/components/admin/empty-state.tsx +24 -0
- package/templates/nextjs-standalone/src/ui/components/admin/entity-detail.tsx +233 -0
- package/templates/nextjs-standalone/src/ui/components/admin/entity-list.tsx +96 -0
- package/templates/nextjs-standalone/src/ui/components/admin/error-banner.tsx +22 -0
- package/templates/nextjs-standalone/src/ui/components/admin/feature-disabled.tsx +44 -0
- package/templates/nextjs-standalone/src/ui/components/admin/health-badge.tsx +30 -0
- package/templates/nextjs-standalone/src/ui/components/admin/loading-state.tsx +14 -0
- package/templates/nextjs-standalone/src/ui/components/admin/stat-card.tsx +32 -0
- package/templates/nextjs-standalone/src/ui/components/atlas-chat.tsx +370 -0
- package/templates/nextjs-standalone/src/ui/components/chart/chart-detection.ts +261 -0
- package/templates/nextjs-standalone/src/ui/components/chart/result-chart.tsx +375 -0
- package/templates/nextjs-standalone/src/ui/components/chat/api-key-bar.tsx +66 -0
- package/templates/nextjs-standalone/src/ui/components/chat/copy-button.tsx +25 -0
- package/templates/nextjs-standalone/src/ui/components/chat/data-table.tsx +102 -0
- package/templates/nextjs-standalone/src/ui/components/chat/error-banner.tsx +32 -0
- package/templates/nextjs-standalone/src/ui/components/chat/explore-card.tsx +41 -0
- package/templates/nextjs-standalone/src/ui/components/chat/loading-card.tsx +10 -0
- package/templates/nextjs-standalone/src/ui/components/chat/managed-auth-card.tsx +116 -0
- package/templates/nextjs-standalone/src/ui/components/chat/markdown.tsx +72 -0
- package/templates/nextjs-standalone/src/ui/components/chat/sql-block.tsx +30 -0
- package/templates/nextjs-standalone/src/ui/components/chat/sql-result-card.tsx +144 -0
- package/templates/nextjs-standalone/src/ui/components/chat/starter-prompts.ts +6 -0
- package/templates/nextjs-standalone/src/ui/components/chat/tool-part.tsx +40 -0
- package/templates/nextjs-standalone/src/ui/components/chat/typing-indicator.tsx +19 -0
- package/templates/nextjs-standalone/src/ui/components/conversations/conversation-item.tsx +120 -0
- package/templates/nextjs-standalone/src/ui/components/conversations/conversation-list.tsx +66 -0
- package/templates/nextjs-standalone/src/ui/components/conversations/conversation-sidebar.tsx +78 -0
- package/templates/nextjs-standalone/src/ui/components/conversations/delete-confirmation.tsx +27 -0
- package/templates/nextjs-standalone/src/ui/context.tsx +78 -0
- package/templates/nextjs-standalone/src/ui/hooks/use-admin-fetch.ts +104 -0
- package/templates/nextjs-standalone/src/ui/hooks/use-conversations.ts +184 -0
- package/templates/nextjs-standalone/src/ui/hooks/use-dark-mode.ts +17 -0
- package/templates/nextjs-standalone/src/ui/lib/action-types.ts +63 -0
- package/templates/nextjs-standalone/src/ui/lib/helpers.ts +104 -0
- package/templates/nextjs-standalone/src/ui/lib/types.ts +145 -0
- package/templates/nextjs-standalone/tsconfig.json +32 -0
- package/templates/nextjs-standalone/vercel.json +4 -0
|
@@ -0,0 +1,542 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import {
|
|
3
|
+
parseEntityYAML,
|
|
4
|
+
profileToSnapshot,
|
|
5
|
+
computeDiff,
|
|
6
|
+
formatDiff,
|
|
7
|
+
mapSQLType,
|
|
8
|
+
} from "../atlas";
|
|
9
|
+
import type { TableProfile, ColumnProfile, EntitySnapshot } from "../atlas";
|
|
10
|
+
|
|
11
|
+
// --- Helpers ---
|
|
12
|
+
|
|
13
|
+
function makeColumn(overrides: Partial<ColumnProfile> = {}): ColumnProfile {
|
|
14
|
+
return {
|
|
15
|
+
name: "col",
|
|
16
|
+
type: "text",
|
|
17
|
+
nullable: false,
|
|
18
|
+
unique_count: null,
|
|
19
|
+
null_count: null,
|
|
20
|
+
sample_values: [],
|
|
21
|
+
is_primary_key: false,
|
|
22
|
+
is_foreign_key: false,
|
|
23
|
+
fk_target_table: null,
|
|
24
|
+
fk_target_column: null,
|
|
25
|
+
is_enum_like: false,
|
|
26
|
+
profiler_notes: [],
|
|
27
|
+
...overrides,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function makeProfile(overrides: Partial<TableProfile> = {}): TableProfile {
|
|
32
|
+
return {
|
|
33
|
+
table_name: "test_table",
|
|
34
|
+
object_type: "table" as const,
|
|
35
|
+
row_count: 100,
|
|
36
|
+
columns: [makeColumn({ name: "id", is_primary_key: true })],
|
|
37
|
+
primary_key_columns: ["id"],
|
|
38
|
+
foreign_keys: [],
|
|
39
|
+
inferred_foreign_keys: [],
|
|
40
|
+
profiler_notes: [],
|
|
41
|
+
table_flags: { possibly_abandoned: false, possibly_denormalized: false },
|
|
42
|
+
...overrides,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function makeSnapshot(
|
|
47
|
+
table: string,
|
|
48
|
+
columns: Record<string, string>,
|
|
49
|
+
fks: string[] = [],
|
|
50
|
+
): EntitySnapshot {
|
|
51
|
+
return {
|
|
52
|
+
table,
|
|
53
|
+
columns: new Map(Object.entries(columns)),
|
|
54
|
+
foreignKeys: new Set(fks),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// --- parseEntityYAML ---
|
|
59
|
+
|
|
60
|
+
describe("parseEntityYAML", () => {
|
|
61
|
+
test("extracts table name and columns from dimensions", () => {
|
|
62
|
+
const doc = {
|
|
63
|
+
name: "Companies",
|
|
64
|
+
table: "companies",
|
|
65
|
+
dimensions: [
|
|
66
|
+
{ name: "id", sql: "id", type: "number" },
|
|
67
|
+
{ name: "name", sql: "name", type: "string" },
|
|
68
|
+
{ name: "revenue", sql: "revenue", type: "number" },
|
|
69
|
+
],
|
|
70
|
+
};
|
|
71
|
+
const snap = parseEntityYAML(doc);
|
|
72
|
+
expect(snap.table).toBe("companies");
|
|
73
|
+
expect(snap.columns.size).toBe(3);
|
|
74
|
+
expect(snap.columns.get("id")).toBe("number");
|
|
75
|
+
expect(snap.columns.get("name")).toBe("string");
|
|
76
|
+
expect(snap.columns.get("revenue")).toBe("number");
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test("skips virtual dimensions", () => {
|
|
80
|
+
const doc = {
|
|
81
|
+
table: "people",
|
|
82
|
+
dimensions: [
|
|
83
|
+
{ name: "id", sql: "id", type: "number" },
|
|
84
|
+
{ name: "age_bucket", sql: "CASE WHEN ...", type: "string", virtual: true },
|
|
85
|
+
{ name: "hire_date_year", sql: "EXTRACT(YEAR FROM hire_date)", type: "number", virtual: true },
|
|
86
|
+
],
|
|
87
|
+
};
|
|
88
|
+
const snap = parseEntityYAML(doc);
|
|
89
|
+
expect(snap.columns.size).toBe(1);
|
|
90
|
+
expect(snap.columns.has("id")).toBe(true);
|
|
91
|
+
expect(snap.columns.has("age_bucket")).toBe(false);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test("extracts FKs from joins", () => {
|
|
95
|
+
const doc = {
|
|
96
|
+
table: "accounts",
|
|
97
|
+
dimensions: [
|
|
98
|
+
{ name: "id", sql: "id", type: "number" },
|
|
99
|
+
{ name: "company_id", sql: "company_id", type: "number" },
|
|
100
|
+
],
|
|
101
|
+
joins: [
|
|
102
|
+
{
|
|
103
|
+
target_entity: "Companies",
|
|
104
|
+
relationship: "many_to_one",
|
|
105
|
+
join_columns: { from: "company_id", to: "id" },
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
};
|
|
109
|
+
const snap = parseEntityYAML(doc);
|
|
110
|
+
expect(snap.foreignKeys.size).toBe(1);
|
|
111
|
+
expect(snap.foreignKeys.has("company_id→companies.id")).toBe(true);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test("handles multi-word entity names in FK targets", () => {
|
|
115
|
+
const doc = {
|
|
116
|
+
table: "order_items",
|
|
117
|
+
dimensions: [
|
|
118
|
+
{ name: "id", sql: "id", type: "number" },
|
|
119
|
+
{ name: "sales_order_id", sql: "sales_order_id", type: "number" },
|
|
120
|
+
],
|
|
121
|
+
joins: [
|
|
122
|
+
{
|
|
123
|
+
target_entity: "SalesOrders",
|
|
124
|
+
relationship: "many_to_one",
|
|
125
|
+
join_columns: { from: "sales_order_id", to: "id" },
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
};
|
|
129
|
+
const snap = parseEntityYAML(doc);
|
|
130
|
+
expect(snap.foreignKeys.has("sales_order_id→sales_orders.id")).toBe(true);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test("handles missing joins and dimensions gracefully", () => {
|
|
134
|
+
const doc = { table: "empty_table" };
|
|
135
|
+
const snap = parseEntityYAML(doc);
|
|
136
|
+
expect(snap.table).toBe("empty_table");
|
|
137
|
+
expect(snap.columns.size).toBe(0);
|
|
138
|
+
expect(snap.foreignKeys.size).toBe(0);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test("skips malformed dimensions (missing name or type)", () => {
|
|
142
|
+
const doc = {
|
|
143
|
+
table: "test_table",
|
|
144
|
+
dimensions: [
|
|
145
|
+
{ name: "id", sql: "id", type: "number" },
|
|
146
|
+
{ name: "bad", sql: "bad" }, // missing type
|
|
147
|
+
{ sql: "also_bad", type: "string" }, // missing name
|
|
148
|
+
{ name: 123, sql: "nope", type: "string" }, // non-string name
|
|
149
|
+
],
|
|
150
|
+
};
|
|
151
|
+
const snap = parseEntityYAML(doc);
|
|
152
|
+
expect(snap.columns.size).toBe(1);
|
|
153
|
+
expect(snap.columns.has("id")).toBe(true);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
// --- profileToSnapshot ---
|
|
158
|
+
|
|
159
|
+
describe("profileToSnapshot", () => {
|
|
160
|
+
test("view profiles produce snapshots with empty FK sets", () => {
|
|
161
|
+
const profile = makeProfile({
|
|
162
|
+
table_name: "order_summary",
|
|
163
|
+
object_type: "view",
|
|
164
|
+
columns: [
|
|
165
|
+
makeColumn({ name: "cnt", type: "integer" }),
|
|
166
|
+
makeColumn({ name: "total", type: "real" }),
|
|
167
|
+
],
|
|
168
|
+
primary_key_columns: [],
|
|
169
|
+
foreign_keys: [],
|
|
170
|
+
inferred_foreign_keys: [],
|
|
171
|
+
});
|
|
172
|
+
const snap = profileToSnapshot(profile);
|
|
173
|
+
expect(snap.table).toBe("order_summary");
|
|
174
|
+
expect(snap.columns.size).toBe(2);
|
|
175
|
+
expect(snap.columns.get("cnt")).toBe("number");
|
|
176
|
+
expect(snap.foreignKeys.size).toBe(0);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
test("maps column types using mapSQLType", () => {
|
|
180
|
+
const profile = makeProfile({
|
|
181
|
+
table_name: "users",
|
|
182
|
+
columns: [
|
|
183
|
+
makeColumn({ name: "id", type: "integer" }),
|
|
184
|
+
makeColumn({ name: "name", type: "varchar(255)" }),
|
|
185
|
+
makeColumn({ name: "created_at", type: "timestamp" }),
|
|
186
|
+
makeColumn({ name: "active", type: "boolean" }),
|
|
187
|
+
],
|
|
188
|
+
});
|
|
189
|
+
const snap = profileToSnapshot(profile);
|
|
190
|
+
expect(snap.columns.get("id")).toBe("number");
|
|
191
|
+
expect(snap.columns.get("name")).toBe("string");
|
|
192
|
+
expect(snap.columns.get("created_at")).toBe("date");
|
|
193
|
+
expect(snap.columns.get("active")).toBe("boolean");
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
test("combines constraint and inferred FKs", () => {
|
|
197
|
+
const profile = makeProfile({
|
|
198
|
+
table_name: "orders",
|
|
199
|
+
foreign_keys: [
|
|
200
|
+
{ from_column: "customer_id", to_table: "customers", to_column: "id", source: "constraint" },
|
|
201
|
+
],
|
|
202
|
+
inferred_foreign_keys: [
|
|
203
|
+
{ from_column: "product_id", to_table: "products", to_column: "id", source: "inferred" },
|
|
204
|
+
],
|
|
205
|
+
});
|
|
206
|
+
const snap = profileToSnapshot(profile);
|
|
207
|
+
expect(snap.foreignKeys.has("customer_id→customers.id")).toBe(true);
|
|
208
|
+
expect(snap.foreignKeys.has("product_id→products.id")).toBe(true);
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
// --- computeDiff ---
|
|
213
|
+
|
|
214
|
+
describe("computeDiff", () => {
|
|
215
|
+
test("no drift — identical snapshots", () => {
|
|
216
|
+
const db = new Map([
|
|
217
|
+
["users", makeSnapshot("users", { id: "number", name: "string" })],
|
|
218
|
+
]);
|
|
219
|
+
const yml = new Map([
|
|
220
|
+
["users", makeSnapshot("users", { id: "number", name: "string" })],
|
|
221
|
+
]);
|
|
222
|
+
const diff = computeDiff(db, yml);
|
|
223
|
+
expect(diff.newTables).toEqual([]);
|
|
224
|
+
expect(diff.removedTables).toEqual([]);
|
|
225
|
+
expect(diff.tableDiffs).toEqual([]);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
test("detects new table in DB", () => {
|
|
229
|
+
const db = new Map([
|
|
230
|
+
["users", makeSnapshot("users", { id: "number" })],
|
|
231
|
+
["audit_logs", makeSnapshot("audit_logs", { id: "number", action: "string" })],
|
|
232
|
+
]);
|
|
233
|
+
const yml = new Map([
|
|
234
|
+
["users", makeSnapshot("users", { id: "number" })],
|
|
235
|
+
]);
|
|
236
|
+
const diff = computeDiff(db, yml);
|
|
237
|
+
expect(diff.newTables).toEqual(["audit_logs"]);
|
|
238
|
+
expect(diff.removedTables).toEqual([]);
|
|
239
|
+
expect(diff.tableDiffs).toEqual([]);
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
test("detects removed table from YAML", () => {
|
|
243
|
+
const db = new Map([
|
|
244
|
+
["users", makeSnapshot("users", { id: "number" })],
|
|
245
|
+
]);
|
|
246
|
+
const yml = new Map([
|
|
247
|
+
["users", makeSnapshot("users", { id: "number" })],
|
|
248
|
+
["old_accounts", makeSnapshot("old_accounts", { id: "number" })],
|
|
249
|
+
]);
|
|
250
|
+
const diff = computeDiff(db, yml);
|
|
251
|
+
expect(diff.newTables).toEqual([]);
|
|
252
|
+
expect(diff.removedTables).toEqual(["old_accounts"]);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
test("detects added column", () => {
|
|
256
|
+
const db = new Map([
|
|
257
|
+
["users", makeSnapshot("users", { id: "number", name: "string", email: "string" })],
|
|
258
|
+
]);
|
|
259
|
+
const yml = new Map([
|
|
260
|
+
["users", makeSnapshot("users", { id: "number", name: "string" })],
|
|
261
|
+
]);
|
|
262
|
+
const diff = computeDiff(db, yml);
|
|
263
|
+
expect(diff.tableDiffs).toHaveLength(1);
|
|
264
|
+
expect(diff.tableDiffs[0].addedColumns).toEqual([{ name: "email", type: "string" }]);
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
test("detects removed column", () => {
|
|
268
|
+
const db = new Map([
|
|
269
|
+
["users", makeSnapshot("users", { id: "number" })],
|
|
270
|
+
]);
|
|
271
|
+
const yml = new Map([
|
|
272
|
+
["users", makeSnapshot("users", { id: "number", legacy_code: "string" })],
|
|
273
|
+
]);
|
|
274
|
+
const diff = computeDiff(db, yml);
|
|
275
|
+
expect(diff.tableDiffs).toHaveLength(1);
|
|
276
|
+
expect(diff.tableDiffs[0].removedColumns).toEqual([{ name: "legacy_code", type: "string" }]);
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
test("detects type change", () => {
|
|
280
|
+
const db = new Map([
|
|
281
|
+
["users", makeSnapshot("users", { id: "number", revenue: "number" })],
|
|
282
|
+
]);
|
|
283
|
+
const yml = new Map([
|
|
284
|
+
["users", makeSnapshot("users", { id: "number", revenue: "string" })],
|
|
285
|
+
]);
|
|
286
|
+
const diff = computeDiff(db, yml);
|
|
287
|
+
expect(diff.tableDiffs).toHaveLength(1);
|
|
288
|
+
expect(diff.tableDiffs[0].typeChanges).toEqual([
|
|
289
|
+
{ name: "revenue", yamlType: "string", dbType: "number" },
|
|
290
|
+
]);
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
test("detects FK added", () => {
|
|
294
|
+
const db = new Map([
|
|
295
|
+
["orders", makeSnapshot("orders", { id: "number" }, ["customer_id→customers.id"])],
|
|
296
|
+
]);
|
|
297
|
+
const yml = new Map([
|
|
298
|
+
["orders", makeSnapshot("orders", { id: "number" })],
|
|
299
|
+
]);
|
|
300
|
+
const diff = computeDiff(db, yml);
|
|
301
|
+
expect(diff.tableDiffs).toHaveLength(1);
|
|
302
|
+
expect(diff.tableDiffs[0].addedFKs).toEqual(["customer_id→customers.id"]);
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
test("detects FK removed", () => {
|
|
306
|
+
const db = new Map([
|
|
307
|
+
["orders", makeSnapshot("orders", { id: "number" })],
|
|
308
|
+
]);
|
|
309
|
+
const yml = new Map([
|
|
310
|
+
["orders", makeSnapshot("orders", { id: "number" }, ["customer_id→customers.id"])],
|
|
311
|
+
]);
|
|
312
|
+
const diff = computeDiff(db, yml);
|
|
313
|
+
expect(diff.tableDiffs).toHaveLength(1);
|
|
314
|
+
expect(diff.tableDiffs[0].removedFKs).toEqual(["customer_id→customers.id"]);
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
test("mixed changes across multiple tables", () => {
|
|
318
|
+
const db = new Map([
|
|
319
|
+
["users", makeSnapshot("users", { id: "number", name: "string", email: "string" })],
|
|
320
|
+
["orders", makeSnapshot("orders", { id: "number", total: "number" }, ["user_id→users.id"])],
|
|
321
|
+
["new_table", makeSnapshot("new_table", { id: "number" })],
|
|
322
|
+
]);
|
|
323
|
+
const yml = new Map([
|
|
324
|
+
["users", makeSnapshot("users", { id: "number", name: "string", old_col: "boolean" })],
|
|
325
|
+
["orders", makeSnapshot("orders", { id: "number", total: "string" })],
|
|
326
|
+
["deleted_table", makeSnapshot("deleted_table", { id: "number" })],
|
|
327
|
+
]);
|
|
328
|
+
const diff = computeDiff(db, yml);
|
|
329
|
+
expect(diff.newTables).toEqual(["new_table"]);
|
|
330
|
+
expect(diff.removedTables).toEqual(["deleted_table"]);
|
|
331
|
+
expect(diff.tableDiffs).toHaveLength(2);
|
|
332
|
+
|
|
333
|
+
const usersDiff = diff.tableDiffs.find((td) => td.table === "users")!;
|
|
334
|
+
expect(usersDiff.addedColumns).toEqual([{ name: "email", type: "string" }]);
|
|
335
|
+
expect(usersDiff.removedColumns).toEqual([{ name: "old_col", type: "boolean" }]);
|
|
336
|
+
|
|
337
|
+
const ordersDiff = diff.tableDiffs.find((td) => td.table === "orders")!;
|
|
338
|
+
expect(ordersDiff.typeChanges).toEqual([{ name: "total", yamlType: "string", dbType: "number" }]);
|
|
339
|
+
expect(ordersDiff.addedFKs).toEqual(["user_id→users.id"]);
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
test("no diff for shared table with identical schema", () => {
|
|
343
|
+
const db = new Map([
|
|
344
|
+
["users", makeSnapshot("users", { id: "number", name: "string" }, ["company_id→companies.id"])],
|
|
345
|
+
]);
|
|
346
|
+
const yml = new Map([
|
|
347
|
+
["users", makeSnapshot("users", { id: "number", name: "string" }, ["company_id→companies.id"])],
|
|
348
|
+
]);
|
|
349
|
+
const diff = computeDiff(db, yml);
|
|
350
|
+
expect(diff.tableDiffs).toEqual([]);
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
test("both maps empty → no drift", () => {
|
|
354
|
+
const db = new Map<string, EntitySnapshot>();
|
|
355
|
+
const yml = new Map<string, EntitySnapshot>();
|
|
356
|
+
const diff = computeDiff(db, yml);
|
|
357
|
+
expect(diff.newTables).toEqual([]);
|
|
358
|
+
expect(diff.removedTables).toEqual([]);
|
|
359
|
+
expect(diff.tableDiffs).toEqual([]);
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
test("DB populated + YAML empty → all tables are new (sorted)", () => {
|
|
363
|
+
const db = new Map([
|
|
364
|
+
["zebras", makeSnapshot("zebras", { id: "number" })],
|
|
365
|
+
["alpacas", makeSnapshot("alpacas", { id: "number" })],
|
|
366
|
+
]);
|
|
367
|
+
const yml = new Map<string, EntitySnapshot>();
|
|
368
|
+
const diff = computeDiff(db, yml);
|
|
369
|
+
expect(diff.newTables).toEqual(["alpacas", "zebras"]);
|
|
370
|
+
expect(diff.removedTables).toEqual([]);
|
|
371
|
+
expect(diff.tableDiffs).toEqual([]);
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
test("DB empty + YAML populated → all tables are removed", () => {
|
|
375
|
+
const db = new Map<string, EntitySnapshot>();
|
|
376
|
+
const yml = new Map([
|
|
377
|
+
["orders", makeSnapshot("orders", { id: "number" })],
|
|
378
|
+
["customers", makeSnapshot("customers", { id: "number" })],
|
|
379
|
+
]);
|
|
380
|
+
const diff = computeDiff(db, yml);
|
|
381
|
+
expect(diff.newTables).toEqual([]);
|
|
382
|
+
expect(diff.removedTables).toEqual(["customers", "orders"]);
|
|
383
|
+
expect(diff.tableDiffs).toEqual([]);
|
|
384
|
+
});
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
// --- formatDiff ---
|
|
388
|
+
|
|
389
|
+
describe("formatDiff", () => {
|
|
390
|
+
test("no drift message", () => {
|
|
391
|
+
const diff = { newTables: [], removedTables: [], tableDiffs: [] };
|
|
392
|
+
const output = formatDiff(diff);
|
|
393
|
+
expect(output).toContain("No drift detected");
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
test("formats new tables", () => {
|
|
397
|
+
const diff = { newTables: ["audit_logs"], removedTables: [], tableDiffs: [] };
|
|
398
|
+
const dbSnaps = new Map([
|
|
399
|
+
["audit_logs", makeSnapshot("audit_logs", { id: "number", action: "string" })],
|
|
400
|
+
]);
|
|
401
|
+
const output = formatDiff(diff, dbSnaps);
|
|
402
|
+
expect(output).toContain("+ audit_logs (2 columns)");
|
|
403
|
+
expect(output).toContain("Summary: 1 new table");
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
test("formats removed tables", () => {
|
|
407
|
+
const diff = { newTables: [], removedTables: ["old_stuff"], tableDiffs: [] };
|
|
408
|
+
const output = formatDiff(diff);
|
|
409
|
+
expect(output).toContain("- old_stuff");
|
|
410
|
+
expect(output).toContain("Summary: 1 removed");
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
test("formats column changes", () => {
|
|
414
|
+
const diff = {
|
|
415
|
+
newTables: [],
|
|
416
|
+
removedTables: [],
|
|
417
|
+
tableDiffs: [
|
|
418
|
+
{
|
|
419
|
+
table: "users",
|
|
420
|
+
addedColumns: [{ name: "email", type: "string" }],
|
|
421
|
+
removedColumns: [{ name: "old_col", type: "string" }],
|
|
422
|
+
typeChanges: [{ name: "revenue", yamlType: "string", dbType: "number" }],
|
|
423
|
+
addedFKs: ["company_id→companies.id"],
|
|
424
|
+
removedFKs: [],
|
|
425
|
+
metadataChanges: [],
|
|
426
|
+
},
|
|
427
|
+
],
|
|
428
|
+
};
|
|
429
|
+
const output = formatDiff(diff);
|
|
430
|
+
expect(output).toContain("+ added column: email (string)");
|
|
431
|
+
expect(output).toContain("- removed column: old_col (string)");
|
|
432
|
+
expect(output).toContain("~ type changed: revenue — YAML: string, DB: number");
|
|
433
|
+
expect(output).toContain("+ added FK: company_id→companies.id");
|
|
434
|
+
expect(output).toContain("1 changed (1 column added, 1 removed, 1 type change, 1 FK added)");
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
test("formats removed FKs", () => {
|
|
438
|
+
const diff = {
|
|
439
|
+
newTables: [],
|
|
440
|
+
removedTables: [],
|
|
441
|
+
tableDiffs: [
|
|
442
|
+
{
|
|
443
|
+
table: "orders",
|
|
444
|
+
addedColumns: [],
|
|
445
|
+
removedColumns: [],
|
|
446
|
+
typeChanges: [],
|
|
447
|
+
addedFKs: [],
|
|
448
|
+
removedFKs: ["old_ref→old_table.id"],
|
|
449
|
+
metadataChanges: [],
|
|
450
|
+
},
|
|
451
|
+
],
|
|
452
|
+
};
|
|
453
|
+
const output = formatDiff(diff);
|
|
454
|
+
expect(output).toContain("- removed FK: old_ref→old_table.id");
|
|
455
|
+
expect(output).toContain("1 FK removed");
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
test("pluralization with multiple new tables and added columns", () => {
|
|
459
|
+
const diff = {
|
|
460
|
+
newTables: ["table_a", "table_b"],
|
|
461
|
+
removedTables: [],
|
|
462
|
+
tableDiffs: [
|
|
463
|
+
{
|
|
464
|
+
table: "users",
|
|
465
|
+
addedColumns: [
|
|
466
|
+
{ name: "email", type: "string" },
|
|
467
|
+
{ name: "phone", type: "string" },
|
|
468
|
+
],
|
|
469
|
+
removedColumns: [],
|
|
470
|
+
typeChanges: [],
|
|
471
|
+
addedFKs: [],
|
|
472
|
+
removedFKs: [],
|
|
473
|
+
metadataChanges: [],
|
|
474
|
+
},
|
|
475
|
+
],
|
|
476
|
+
};
|
|
477
|
+
const output = formatDiff(diff);
|
|
478
|
+
expect(output).toContain("2 new tables");
|
|
479
|
+
expect(output).toContain("2 columns added");
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
test("no dbSnapshots for new tables — no column count in output", () => {
|
|
483
|
+
const diff = {
|
|
484
|
+
newTables: ["audit_logs"],
|
|
485
|
+
removedTables: [],
|
|
486
|
+
tableDiffs: [],
|
|
487
|
+
};
|
|
488
|
+
const output = formatDiff(diff);
|
|
489
|
+
expect(output).toContain("audit_logs");
|
|
490
|
+
expect(output).not.toContain("columns)");
|
|
491
|
+
});
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
// --- mapSQLType (used by diff) ---
|
|
495
|
+
|
|
496
|
+
describe("mapSQLType", () => {
|
|
497
|
+
test("integer types → number", () => {
|
|
498
|
+
expect(mapSQLType("integer")).toBe("number");
|
|
499
|
+
expect(mapSQLType("INT")).toBe("number");
|
|
500
|
+
expect(mapSQLType("bigint")).toBe("number");
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
test("float types → number", () => {
|
|
504
|
+
expect(mapSQLType("float")).toBe("number");
|
|
505
|
+
expect(mapSQLType("real")).toBe("number");
|
|
506
|
+
expect(mapSQLType("numeric(10,2)")).toBe("number");
|
|
507
|
+
expect(mapSQLType("decimal")).toBe("number");
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
test("boolean → boolean", () => {
|
|
511
|
+
expect(mapSQLType("boolean")).toBe("boolean");
|
|
512
|
+
expect(mapSQLType("bool")).toBe("boolean");
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
test("date/time types → date", () => {
|
|
516
|
+
expect(mapSQLType("date")).toBe("date");
|
|
517
|
+
expect(mapSQLType("timestamp")).toBe("date");
|
|
518
|
+
expect(mapSQLType("timestamptz")).toBe("date");
|
|
519
|
+
expect(mapSQLType("time")).toBe("date");
|
|
520
|
+
});
|
|
521
|
+
|
|
522
|
+
test("text types → string", () => {
|
|
523
|
+
expect(mapSQLType("text")).toBe("string");
|
|
524
|
+
expect(mapSQLType("varchar(255)")).toBe("string");
|
|
525
|
+
expect(mapSQLType("character varying")).toBe("string");
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
test("interval type → string (not number)", () => {
|
|
529
|
+
expect(mapSQLType("interval")).toBe("string");
|
|
530
|
+
expect(mapSQLType("INTERVAL")).toBe("string");
|
|
531
|
+
expect(mapSQLType("interval day to second")).toBe("string");
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
test("exotic/unknown types fallback → string", () => {
|
|
535
|
+
expect(mapSQLType("jsonb")).toBe("string");
|
|
536
|
+
expect(mapSQLType("uuid")).toBe("string");
|
|
537
|
+
expect(mapSQLType("bytea")).toBe("string");
|
|
538
|
+
expect(mapSQLType("inet")).toBe("string");
|
|
539
|
+
expect(mapSQLType("tsvector")).toBe("string");
|
|
540
|
+
expect(mapSQLType("USER-DEFINED")).toBe("string");
|
|
541
|
+
});
|
|
542
|
+
});
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import * as yaml from "js-yaml";
|
|
3
|
+
import type { TableProfile, ColumnProfile } from "../atlas";
|
|
4
|
+
import { generateEntityYAML, generateMetricYAML } from "../atlas";
|
|
5
|
+
|
|
6
|
+
// --- Helpers ---
|
|
7
|
+
|
|
8
|
+
function makeColumn(overrides: Partial<ColumnProfile> = {}): ColumnProfile {
|
|
9
|
+
return {
|
|
10
|
+
name: "col",
|
|
11
|
+
type: "text",
|
|
12
|
+
nullable: false,
|
|
13
|
+
unique_count: null,
|
|
14
|
+
null_count: null,
|
|
15
|
+
sample_values: [],
|
|
16
|
+
is_primary_key: false,
|
|
17
|
+
is_foreign_key: false,
|
|
18
|
+
fk_target_table: null,
|
|
19
|
+
fk_target_column: null,
|
|
20
|
+
is_enum_like: false,
|
|
21
|
+
profiler_notes: [],
|
|
22
|
+
...overrides,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function makeViewProfile(overrides: Partial<TableProfile> = {}): TableProfile {
|
|
27
|
+
return {
|
|
28
|
+
table_name: "order_summary",
|
|
29
|
+
object_type: "view" as const,
|
|
30
|
+
row_count: 1500,
|
|
31
|
+
columns: [
|
|
32
|
+
makeColumn({ name: "region", type: "text", sample_values: ["US", "EU", "APAC"] }),
|
|
33
|
+
makeColumn({ name: "total_orders", type: "integer" }),
|
|
34
|
+
makeColumn({ name: "total_revenue", type: "numeric", sample_values: ["12345.67", "98765.43"] }),
|
|
35
|
+
makeColumn({ name: "avg_order_value", type: "real" }),
|
|
36
|
+
],
|
|
37
|
+
primary_key_columns: [],
|
|
38
|
+
foreign_keys: [],
|
|
39
|
+
inferred_foreign_keys: [],
|
|
40
|
+
profiler_notes: [],
|
|
41
|
+
table_flags: { possibly_abandoned: false, possibly_denormalized: false },
|
|
42
|
+
...overrides,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// --- generateEntityYAML with view profiles ---
|
|
47
|
+
|
|
48
|
+
describe("generateEntityYAML (views)", () => {
|
|
49
|
+
test("produces type 'view' for view profiles", () => {
|
|
50
|
+
const profile = makeViewProfile();
|
|
51
|
+
const result = generateEntityYAML(profile, [profile], "postgres");
|
|
52
|
+
const doc = yaml.load(result) as Record<string, unknown>;
|
|
53
|
+
|
|
54
|
+
expect(doc.type).toBe("view");
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test("does not include measures section for views", () => {
|
|
58
|
+
const profile = makeViewProfile();
|
|
59
|
+
const result = generateEntityYAML(profile, [profile], "postgres");
|
|
60
|
+
const doc = yaml.load(result) as Record<string, unknown>;
|
|
61
|
+
|
|
62
|
+
expect(doc.measures).toBeUndefined();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test("does not include query_patterns section for views", () => {
|
|
66
|
+
const profile = makeViewProfile();
|
|
67
|
+
const result = generateEntityYAML(profile, [profile], "postgres");
|
|
68
|
+
const doc = yaml.load(result) as Record<string, unknown>;
|
|
69
|
+
|
|
70
|
+
expect(doc.query_patterns).toBeUndefined();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test("description starts with 'Database view:'", () => {
|
|
74
|
+
const profile = makeViewProfile();
|
|
75
|
+
const result = generateEntityYAML(profile, [profile], "postgres");
|
|
76
|
+
const doc = yaml.load(result) as Record<string, unknown>;
|
|
77
|
+
|
|
78
|
+
expect(typeof doc.description).toBe("string");
|
|
79
|
+
expect((doc.description as string).startsWith("Database view:")).toBe(true);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("grain mentions 'view'", () => {
|
|
83
|
+
const profile = makeViewProfile();
|
|
84
|
+
const result = generateEntityYAML(profile, [profile], "postgres");
|
|
85
|
+
const doc = yaml.load(result) as Record<string, unknown>;
|
|
86
|
+
|
|
87
|
+
expect(typeof doc.grain).toBe("string");
|
|
88
|
+
expect((doc.grain as string).toLowerCase()).toContain("view");
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test("use_cases includes database view note", () => {
|
|
92
|
+
const profile = makeViewProfile();
|
|
93
|
+
const result = generateEntityYAML(profile, [profile], "postgres");
|
|
94
|
+
const doc = yaml.load(result) as Record<string, unknown>;
|
|
95
|
+
|
|
96
|
+
const useCases = doc.use_cases as string[];
|
|
97
|
+
expect(Array.isArray(useCases)).toBe(true);
|
|
98
|
+
expect(useCases.some((uc) => uc.toLowerCase().includes("database view"))).toBe(true);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test("dimensions are still generated for view columns", () => {
|
|
102
|
+
const profile = makeViewProfile();
|
|
103
|
+
const result = generateEntityYAML(profile, [profile], "postgres");
|
|
104
|
+
const doc = yaml.load(result) as Record<string, unknown>;
|
|
105
|
+
|
|
106
|
+
const dimensions = doc.dimensions as Record<string, unknown>[];
|
|
107
|
+
expect(Array.isArray(dimensions)).toBe(true);
|
|
108
|
+
// Should have at least the 4 base columns (may also have virtual dims)
|
|
109
|
+
const baseNames = dimensions.filter((d) => !d.virtual).map((d) => d.name);
|
|
110
|
+
expect(baseNames).toContain("region");
|
|
111
|
+
expect(baseNames).toContain("total_orders");
|
|
112
|
+
expect(baseNames).toContain("total_revenue");
|
|
113
|
+
expect(baseNames).toContain("avg_order_value");
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test("no joins are generated for view with no FKs", () => {
|
|
117
|
+
const profile = makeViewProfile();
|
|
118
|
+
const result = generateEntityYAML(profile, [profile], "postgres");
|
|
119
|
+
const doc = yaml.load(result) as Record<string, unknown>;
|
|
120
|
+
|
|
121
|
+
expect(doc.joins).toBeUndefined();
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// --- generateMetricYAML with view profiles ---
|
|
126
|
+
|
|
127
|
+
describe("generateMetricYAML (views)", () => {
|
|
128
|
+
test("returns null for view profiles even with numeric columns", () => {
|
|
129
|
+
const profile = makeViewProfile();
|
|
130
|
+
const result = generateMetricYAML(profile);
|
|
131
|
+
|
|
132
|
+
expect(result).toBeNull();
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test("returns null for view profiles with no numeric columns", () => {
|
|
136
|
+
const profile = makeViewProfile({
|
|
137
|
+
columns: [
|
|
138
|
+
makeColumn({ name: "name", type: "text" }),
|
|
139
|
+
makeColumn({ name: "status", type: "text" }),
|
|
140
|
+
],
|
|
141
|
+
});
|
|
142
|
+
const result = generateMetricYAML(profile);
|
|
143
|
+
|
|
144
|
+
expect(result).toBeNull();
|
|
145
|
+
});
|
|
146
|
+
});
|