@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,521 @@
|
|
|
1
|
+
import { describe, test, expect } from "bun:test";
|
|
2
|
+
import {
|
|
3
|
+
generateMigrationSQL,
|
|
4
|
+
applyMigrations,
|
|
5
|
+
ensureMigrationsTable,
|
|
6
|
+
getAppliedMigrations,
|
|
7
|
+
diffSchema,
|
|
8
|
+
prefixTableName,
|
|
9
|
+
type MigrateDB,
|
|
10
|
+
type MigrationStatement,
|
|
11
|
+
} from "../migrate";
|
|
12
|
+
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
// Mock DB
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
|
|
17
|
+
interface QueryLog {
|
|
18
|
+
sql: string;
|
|
19
|
+
params?: unknown[];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function makeMockDB(opts?: {
|
|
23
|
+
existingMigrations?: Array<{ plugin_id: string; table_name: string; sql_hash: string }>;
|
|
24
|
+
existingTables?: string[];
|
|
25
|
+
failOnCreate?: boolean;
|
|
26
|
+
}): MigrateDB & { queries: QueryLog[] } {
|
|
27
|
+
const queries: QueryLog[] = [];
|
|
28
|
+
const existingMigrations = opts?.existingMigrations ?? [];
|
|
29
|
+
const existingTables = opts?.existingTables ?? [];
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
queries,
|
|
33
|
+
async query(sql: string, params?: unknown[]) {
|
|
34
|
+
queries.push({ sql, params });
|
|
35
|
+
|
|
36
|
+
if (opts?.failOnCreate && sql.includes("CREATE TABLE") && !sql.includes("plugin_migrations")) {
|
|
37
|
+
throw new Error("permission denied for schema public");
|
|
38
|
+
}
|
|
39
|
+
if (sql.includes("FROM plugin_migrations")) {
|
|
40
|
+
return { rows: existingMigrations };
|
|
41
|
+
}
|
|
42
|
+
if (sql.includes("FROM pg_tables")) {
|
|
43
|
+
return { rows: existingTables.map((t) => ({ tablename: t })) };
|
|
44
|
+
}
|
|
45
|
+
return { rows: [] };
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// ---------------------------------------------------------------------------
|
|
51
|
+
// Helpers
|
|
52
|
+
// ---------------------------------------------------------------------------
|
|
53
|
+
|
|
54
|
+
function makePlugin(
|
|
55
|
+
id: string,
|
|
56
|
+
schema: Record<string, { fields: Record<string, unknown> }>,
|
|
57
|
+
) {
|
|
58
|
+
return { id, schema };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// ---------------------------------------------------------------------------
|
|
62
|
+
// prefixTableName
|
|
63
|
+
// ---------------------------------------------------------------------------
|
|
64
|
+
|
|
65
|
+
describe("prefixTableName", () => {
|
|
66
|
+
test("basic prefixing", () => {
|
|
67
|
+
expect(prefixTableName("jira", "tickets")).toBe("plugin_jira_tickets");
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test("replaces dashes with underscores", () => {
|
|
71
|
+
expect(prefixTableName("my-plugin", "user-tokens")).toBe("plugin_my_plugin_user_tokens");
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test("replaces dots with underscores", () => {
|
|
75
|
+
expect(prefixTableName("com.example", "data")).toBe("plugin_com_example_data");
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// ---------------------------------------------------------------------------
|
|
80
|
+
// generateMigrationSQL
|
|
81
|
+
// ---------------------------------------------------------------------------
|
|
82
|
+
|
|
83
|
+
describe("generateMigrationSQL", () => {
|
|
84
|
+
test("generates CREATE TABLE for string, number, boolean, date types", () => {
|
|
85
|
+
const plugins = [
|
|
86
|
+
makePlugin("test", {
|
|
87
|
+
items: {
|
|
88
|
+
fields: {
|
|
89
|
+
name: { type: "string", required: true },
|
|
90
|
+
count: { type: "number" },
|
|
91
|
+
active: { type: "boolean" },
|
|
92
|
+
due_date: { type: "date" },
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
}),
|
|
96
|
+
];
|
|
97
|
+
|
|
98
|
+
const stmts = generateMigrationSQL(plugins as Parameters<typeof generateMigrationSQL>[0]);
|
|
99
|
+
expect(stmts).toHaveLength(1);
|
|
100
|
+
|
|
101
|
+
const sql = stmts[0].sql;
|
|
102
|
+
expect(sql).toContain('CREATE TABLE IF NOT EXISTS "plugin_test_items"');
|
|
103
|
+
expect(sql).toContain('"name" TEXT NOT NULL');
|
|
104
|
+
expect(sql).toContain('"count" INTEGER');
|
|
105
|
+
expect(sql).toContain('"active" BOOLEAN');
|
|
106
|
+
expect(sql).toContain('"due_date" TIMESTAMPTZ');
|
|
107
|
+
expect(sql).toContain('"id" UUID PRIMARY KEY DEFAULT gen_random_uuid()');
|
|
108
|
+
expect(sql).toContain('"created_at" TIMESTAMPTZ DEFAULT now()');
|
|
109
|
+
expect(sql).toContain('"updated_at" TIMESTAMPTZ DEFAULT now()');
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test("handles UNIQUE constraint", () => {
|
|
113
|
+
const plugins = [
|
|
114
|
+
makePlugin("test", {
|
|
115
|
+
users: {
|
|
116
|
+
fields: {
|
|
117
|
+
email: { type: "string", required: true, unique: true },
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
}),
|
|
121
|
+
];
|
|
122
|
+
|
|
123
|
+
const stmts = generateMigrationSQL(plugins as Parameters<typeof generateMigrationSQL>[0]);
|
|
124
|
+
expect(stmts[0].sql).toContain('"email" TEXT NOT NULL UNIQUE');
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test("handles DEFAULT values", () => {
|
|
128
|
+
const plugins = [
|
|
129
|
+
makePlugin("test", {
|
|
130
|
+
settings: {
|
|
131
|
+
fields: {
|
|
132
|
+
label: { type: "string", defaultValue: "untitled" },
|
|
133
|
+
priority: { type: "number", defaultValue: 0 },
|
|
134
|
+
enabled: { type: "boolean", defaultValue: true },
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
}),
|
|
138
|
+
];
|
|
139
|
+
|
|
140
|
+
const stmts = generateMigrationSQL(plugins as Parameters<typeof generateMigrationSQL>[0]);
|
|
141
|
+
const sql = stmts[0].sql;
|
|
142
|
+
expect(sql).toContain("DEFAULT 'untitled'");
|
|
143
|
+
expect(sql).toContain("DEFAULT 0");
|
|
144
|
+
expect(sql).toContain("DEFAULT true");
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test("handles FOREIGN KEY references", () => {
|
|
148
|
+
const plugins = [
|
|
149
|
+
makePlugin("test", {
|
|
150
|
+
projects: { fields: { name: { type: "string" } } },
|
|
151
|
+
tasks: {
|
|
152
|
+
fields: {
|
|
153
|
+
project_id: {
|
|
154
|
+
type: "string",
|
|
155
|
+
references: { model: "projects", field: "id" },
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
}),
|
|
160
|
+
];
|
|
161
|
+
|
|
162
|
+
const stmts = generateMigrationSQL(plugins as Parameters<typeof generateMigrationSQL>[0]);
|
|
163
|
+
const taskStmt = stmts.find((s) => s.tableName === "tasks");
|
|
164
|
+
expect(taskStmt).toBeDefined();
|
|
165
|
+
expect(taskStmt!.sql).toContain(
|
|
166
|
+
'FOREIGN KEY ("project_id") REFERENCES "plugin_test_projects"("id")'
|
|
167
|
+
);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
test("escapes single quotes in default values", () => {
|
|
171
|
+
const plugins = [
|
|
172
|
+
makePlugin("test", {
|
|
173
|
+
items: {
|
|
174
|
+
fields: {
|
|
175
|
+
label: { type: "string", defaultValue: "it's a test" },
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
}),
|
|
179
|
+
];
|
|
180
|
+
|
|
181
|
+
const stmts = generateMigrationSQL(plugins as Parameters<typeof generateMigrationSQL>[0]);
|
|
182
|
+
expect(stmts[0].sql).toContain("DEFAULT 'it''s a test'");
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
test("skips plugins without schema", () => {
|
|
186
|
+
const plugins = [{ id: "no-schema" }];
|
|
187
|
+
const stmts = generateMigrationSQL(plugins as Parameters<typeof generateMigrationSQL>[0]);
|
|
188
|
+
expect(stmts).toHaveLength(0);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
test("generates multiple tables from one plugin", () => {
|
|
192
|
+
const plugins = [
|
|
193
|
+
makePlugin("crm", {
|
|
194
|
+
contacts: { fields: { name: { type: "string" } } },
|
|
195
|
+
deals: { fields: { value: { type: "number" } } },
|
|
196
|
+
}),
|
|
197
|
+
];
|
|
198
|
+
|
|
199
|
+
const stmts = generateMigrationSQL(plugins as Parameters<typeof generateMigrationSQL>[0]);
|
|
200
|
+
expect(stmts).toHaveLength(2);
|
|
201
|
+
expect(stmts.map((s) => s.prefixedName).sort()).toEqual([
|
|
202
|
+
"plugin_crm_contacts",
|
|
203
|
+
"plugin_crm_deals",
|
|
204
|
+
]);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
test("generates statements from multiple plugins", () => {
|
|
208
|
+
const plugins = [
|
|
209
|
+
makePlugin("a", { items: { fields: { x: { type: "string" } } } }),
|
|
210
|
+
makePlugin("b", { things: { fields: { y: { type: "number" } } } }),
|
|
211
|
+
];
|
|
212
|
+
|
|
213
|
+
const stmts = generateMigrationSQL(plugins as Parameters<typeof generateMigrationSQL>[0]);
|
|
214
|
+
expect(stmts).toHaveLength(2);
|
|
215
|
+
expect(stmts[0].pluginId).toBe("a");
|
|
216
|
+
expect(stmts[1].pluginId).toBe("b");
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
test("generates deterministic hash for same SQL", () => {
|
|
220
|
+
const plugins = [
|
|
221
|
+
makePlugin("test", { items: { fields: { x: { type: "string" } } } }),
|
|
222
|
+
];
|
|
223
|
+
|
|
224
|
+
const stmts1 = generateMigrationSQL(plugins as Parameters<typeof generateMigrationSQL>[0]);
|
|
225
|
+
const stmts2 = generateMigrationSQL(plugins as Parameters<typeof generateMigrationSQL>[0]);
|
|
226
|
+
expect(stmts1[0].hash).toBe(stmts2[0].hash);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
test("generates different hashes for different SQL", () => {
|
|
230
|
+
const plugins1 = [makePlugin("test", { items: { fields: { x: { type: "string" } } } })];
|
|
231
|
+
const plugins2 = [makePlugin("test", { items: { fields: { x: { type: "number" } } } })];
|
|
232
|
+
|
|
233
|
+
const stmts1 = generateMigrationSQL(plugins1 as Parameters<typeof generateMigrationSQL>[0]);
|
|
234
|
+
const stmts2 = generateMigrationSQL(plugins2 as Parameters<typeof generateMigrationSQL>[0]);
|
|
235
|
+
expect(stmts1[0].hash).not.toBe(stmts2[0].hash);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
test("throws on unknown field type", () => {
|
|
239
|
+
const plugins = [makePlugin("test", { items: { fields: { data: { type: "json" } } } })];
|
|
240
|
+
expect(() => generateMigrationSQL(plugins as Parameters<typeof generateMigrationSQL>[0]))
|
|
241
|
+
.toThrow(/Unknown field type "json"/);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
test("rejects field names with special characters", () => {
|
|
245
|
+
const plugins = [makePlugin("test", {
|
|
246
|
+
items: { fields: { 'foo"; DROP TABLE x; --': { type: "string" } } },
|
|
247
|
+
})];
|
|
248
|
+
expect(() => generateMigrationSQL(plugins as Parameters<typeof generateMigrationSQL>[0]))
|
|
249
|
+
.toThrow(/Invalid identifier/);
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
test("rejects references.field with special characters", () => {
|
|
253
|
+
const plugins = [makePlugin("test", {
|
|
254
|
+
parent: { fields: { name: { type: "string" } } },
|
|
255
|
+
child: {
|
|
256
|
+
fields: {
|
|
257
|
+
parent_id: {
|
|
258
|
+
type: "string",
|
|
259
|
+
references: { model: "parent", field: 'id"); DROP TABLE x; --' },
|
|
260
|
+
},
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
})];
|
|
264
|
+
expect(() => generateMigrationSQL(plugins as Parameters<typeof generateMigrationSQL>[0]))
|
|
265
|
+
.toThrow(/Invalid identifier/);
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
test("rejects NaN as default value", () => {
|
|
269
|
+
const plugins = [makePlugin("test", {
|
|
270
|
+
items: { fields: { count: { type: "number", defaultValue: NaN } } },
|
|
271
|
+
})];
|
|
272
|
+
expect(() => generateMigrationSQL(plugins as Parameters<typeof generateMigrationSQL>[0]))
|
|
273
|
+
.toThrow(/Invalid numeric defaultValue/);
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
test("rejects Infinity as default value", () => {
|
|
277
|
+
const plugins = [makePlugin("test", {
|
|
278
|
+
items: { fields: { count: { type: "number", defaultValue: Infinity } } },
|
|
279
|
+
})];
|
|
280
|
+
expect(() => generateMigrationSQL(plugins as Parameters<typeof generateMigrationSQL>[0]))
|
|
281
|
+
.toThrow(/Invalid numeric defaultValue/);
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
test("rejects unsupported defaultValue types", () => {
|
|
285
|
+
const plugins = [makePlugin("test", {
|
|
286
|
+
items: { fields: { data: { type: "string", defaultValue: { raw: "NOW()" } } } },
|
|
287
|
+
})];
|
|
288
|
+
expect(() => generateMigrationSQL(plugins as Parameters<typeof generateMigrationSQL>[0]))
|
|
289
|
+
.toThrow(/Unsupported defaultValue type/);
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
test("generates table with only auto-columns when fields is empty", () => {
|
|
293
|
+
const plugins = [makePlugin("test", { empty_table: { fields: {} } })];
|
|
294
|
+
const stmts = generateMigrationSQL(plugins as Parameters<typeof generateMigrationSQL>[0]);
|
|
295
|
+
expect(stmts).toHaveLength(1);
|
|
296
|
+
expect(stmts[0].sql).toContain('"id" UUID PRIMARY KEY');
|
|
297
|
+
expect(stmts[0].sql).toContain('"created_at"');
|
|
298
|
+
expect(stmts[0].sql).toContain('"updated_at"');
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
// ---------------------------------------------------------------------------
|
|
303
|
+
// ensureMigrationsTable
|
|
304
|
+
// ---------------------------------------------------------------------------
|
|
305
|
+
|
|
306
|
+
describe("ensureMigrationsTable", () => {
|
|
307
|
+
test("creates the plugin_migrations table", async () => {
|
|
308
|
+
const db = makeMockDB();
|
|
309
|
+
await ensureMigrationsTable(db);
|
|
310
|
+
expect(db.queries).toHaveLength(1);
|
|
311
|
+
expect(db.queries[0].sql).toContain("CREATE TABLE IF NOT EXISTS plugin_migrations");
|
|
312
|
+
});
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
// ---------------------------------------------------------------------------
|
|
316
|
+
// getAppliedMigrations
|
|
317
|
+
// ---------------------------------------------------------------------------
|
|
318
|
+
|
|
319
|
+
describe("getAppliedMigrations", () => {
|
|
320
|
+
test("returns set of applied migration keys", async () => {
|
|
321
|
+
const db = makeMockDB({
|
|
322
|
+
existingMigrations: [
|
|
323
|
+
{ plugin_id: "test", table_name: "items", sql_hash: "abc123" },
|
|
324
|
+
],
|
|
325
|
+
});
|
|
326
|
+
const applied = await getAppliedMigrations(db);
|
|
327
|
+
expect(applied.has("test:items:abc123")).toBe(true);
|
|
328
|
+
expect(applied.size).toBe(1);
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
test("returns empty set when no migrations", async () => {
|
|
332
|
+
const db = makeMockDB();
|
|
333
|
+
const applied = await getAppliedMigrations(db);
|
|
334
|
+
expect(applied.size).toBe(0);
|
|
335
|
+
});
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
// ---------------------------------------------------------------------------
|
|
339
|
+
// applyMigrations
|
|
340
|
+
// ---------------------------------------------------------------------------
|
|
341
|
+
|
|
342
|
+
describe("applyMigrations", () => {
|
|
343
|
+
test("applies new migrations and records them", async () => {
|
|
344
|
+
const db = makeMockDB();
|
|
345
|
+
const stmts: MigrationStatement[] = [
|
|
346
|
+
{
|
|
347
|
+
pluginId: "test",
|
|
348
|
+
tableName: "items",
|
|
349
|
+
prefixedName: "plugin_test_items",
|
|
350
|
+
sql: 'CREATE TABLE IF NOT EXISTS "plugin_test_items" ("id" UUID PRIMARY KEY);',
|
|
351
|
+
hash: "aabb0011",
|
|
352
|
+
},
|
|
353
|
+
];
|
|
354
|
+
|
|
355
|
+
const result = await applyMigrations(db, stmts);
|
|
356
|
+
expect(result.applied).toEqual(["plugin_test_items"]);
|
|
357
|
+
expect(result.skipped).toHaveLength(0);
|
|
358
|
+
|
|
359
|
+
// Should have: ensureMigrationsTable, getAppliedMigrations, CREATE TABLE, INSERT into plugin_migrations
|
|
360
|
+
const createTableQuery = db.queries.find((q) => q.sql.includes("plugin_test_items"));
|
|
361
|
+
expect(createTableQuery).toBeDefined();
|
|
362
|
+
|
|
363
|
+
const insertQuery = db.queries.find((q) => q.sql.includes("INSERT INTO plugin_migrations"));
|
|
364
|
+
expect(insertQuery).toBeDefined();
|
|
365
|
+
expect(insertQuery!.params).toEqual(["test", "items", "aabb0011"]);
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
test("skips already-applied migrations", async () => {
|
|
369
|
+
const db = makeMockDB({
|
|
370
|
+
existingMigrations: [
|
|
371
|
+
{ plugin_id: "test", table_name: "items", sql_hash: "aabb0011" },
|
|
372
|
+
],
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
const stmts: MigrationStatement[] = [
|
|
376
|
+
{
|
|
377
|
+
pluginId: "test",
|
|
378
|
+
tableName: "items",
|
|
379
|
+
prefixedName: "plugin_test_items",
|
|
380
|
+
sql: 'CREATE TABLE IF NOT EXISTS "plugin_test_items" ("id" UUID PRIMARY KEY);',
|
|
381
|
+
hash: "aabb0011",
|
|
382
|
+
},
|
|
383
|
+
];
|
|
384
|
+
|
|
385
|
+
const result = await applyMigrations(db, stmts);
|
|
386
|
+
expect(result.applied).toHaveLength(0);
|
|
387
|
+
expect(result.skipped).toEqual(["plugin_test_items"]);
|
|
388
|
+
|
|
389
|
+
// Should NOT have a CREATE TABLE query (only ensureMigrations + getApplied)
|
|
390
|
+
const createTableQuery = db.queries.find(
|
|
391
|
+
(q) => q.sql.includes("plugin_test_items") && q.sql.includes("CREATE TABLE"),
|
|
392
|
+
);
|
|
393
|
+
expect(createTableQuery).toBeUndefined();
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
test("applies changed migration (different hash)", async () => {
|
|
397
|
+
const db = makeMockDB({
|
|
398
|
+
existingMigrations: [
|
|
399
|
+
{ plugin_id: "test", table_name: "items", sql_hash: "old_hash" },
|
|
400
|
+
],
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
const stmts: MigrationStatement[] = [
|
|
404
|
+
{
|
|
405
|
+
pluginId: "test",
|
|
406
|
+
tableName: "items",
|
|
407
|
+
prefixedName: "plugin_test_items",
|
|
408
|
+
sql: 'CREATE TABLE IF NOT EXISTS "plugin_test_items" ("id" UUID PRIMARY KEY, "name" TEXT);',
|
|
409
|
+
hash: "new_hash",
|
|
410
|
+
},
|
|
411
|
+
];
|
|
412
|
+
|
|
413
|
+
const result = await applyMigrations(db, stmts);
|
|
414
|
+
expect(result.applied).toEqual(["plugin_test_items"]);
|
|
415
|
+
expect(result.skipped).toHaveLength(0);
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
test("handles multiple statements with mixed state", async () => {
|
|
419
|
+
const db = makeMockDB({
|
|
420
|
+
existingMigrations: [
|
|
421
|
+
{ plugin_id: "a", table_name: "existing", sql_hash: "hash1" },
|
|
422
|
+
],
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
const stmts: MigrationStatement[] = [
|
|
426
|
+
{
|
|
427
|
+
pluginId: "a",
|
|
428
|
+
tableName: "existing",
|
|
429
|
+
prefixedName: "plugin_a_existing",
|
|
430
|
+
sql: "CREATE TABLE ...",
|
|
431
|
+
hash: "hash1",
|
|
432
|
+
},
|
|
433
|
+
{
|
|
434
|
+
pluginId: "b",
|
|
435
|
+
tableName: "new_table",
|
|
436
|
+
prefixedName: "plugin_b_new_table",
|
|
437
|
+
sql: "CREATE TABLE ...",
|
|
438
|
+
hash: "hash2",
|
|
439
|
+
},
|
|
440
|
+
];
|
|
441
|
+
|
|
442
|
+
const result = await applyMigrations(db, stmts);
|
|
443
|
+
expect(result.applied).toEqual(["plugin_b_new_table"]);
|
|
444
|
+
expect(result.skipped).toEqual(["plugin_a_existing"]);
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
test("handles empty statements array", async () => {
|
|
448
|
+
const db = makeMockDB();
|
|
449
|
+
const result = await applyMigrations(db, []);
|
|
450
|
+
expect(result.applied).toHaveLength(0);
|
|
451
|
+
expect(result.skipped).toHaveLength(0);
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
test("propagates db errors with context", async () => {
|
|
455
|
+
const db = makeMockDB({ failOnCreate: true });
|
|
456
|
+
const stmts: MigrationStatement[] = [
|
|
457
|
+
{
|
|
458
|
+
pluginId: "test",
|
|
459
|
+
tableName: "items",
|
|
460
|
+
prefixedName: "plugin_test_items",
|
|
461
|
+
sql: 'CREATE TABLE IF NOT EXISTS "plugin_test_items" ("id" UUID PRIMARY KEY);',
|
|
462
|
+
hash: "abc",
|
|
463
|
+
},
|
|
464
|
+
];
|
|
465
|
+
|
|
466
|
+
await expect(applyMigrations(db, stmts)).rejects.toThrow(/plugin_test_items/);
|
|
467
|
+
await expect(applyMigrations(db, stmts)).rejects.toThrow(/permission denied/);
|
|
468
|
+
});
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
// ---------------------------------------------------------------------------
|
|
472
|
+
// diffSchema
|
|
473
|
+
// ---------------------------------------------------------------------------
|
|
474
|
+
|
|
475
|
+
describe("diffSchema", () => {
|
|
476
|
+
test("identifies new and existing tables", async () => {
|
|
477
|
+
const db = makeMockDB({
|
|
478
|
+
existingTables: ["plugin_test_items"],
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
const stmts: MigrationStatement[] = [
|
|
482
|
+
{
|
|
483
|
+
pluginId: "test",
|
|
484
|
+
tableName: "items",
|
|
485
|
+
prefixedName: "plugin_test_items",
|
|
486
|
+
sql: "",
|
|
487
|
+
hash: "",
|
|
488
|
+
},
|
|
489
|
+
{
|
|
490
|
+
pluginId: "test",
|
|
491
|
+
tableName: "users",
|
|
492
|
+
prefixedName: "plugin_test_users",
|
|
493
|
+
sql: "",
|
|
494
|
+
hash: "",
|
|
495
|
+
},
|
|
496
|
+
];
|
|
497
|
+
|
|
498
|
+
const diff = await diffSchema(db, stmts);
|
|
499
|
+
expect(diff.existingTables).toEqual(["plugin_test_items"]);
|
|
500
|
+
expect(diff.newTables).toEqual(["plugin_test_users"]);
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
test("all new when no tables exist", async () => {
|
|
504
|
+
const db = makeMockDB();
|
|
505
|
+
|
|
506
|
+
const stmts: MigrationStatement[] = [
|
|
507
|
+
{ pluginId: "x", tableName: "a", prefixedName: "plugin_x_a", sql: "", hash: "" },
|
|
508
|
+
];
|
|
509
|
+
|
|
510
|
+
const diff = await diffSchema(db, stmts);
|
|
511
|
+
expect(diff.newTables).toEqual(["plugin_x_a"]);
|
|
512
|
+
expect(diff.existingTables).toHaveLength(0);
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
test("returns empty diff for empty statements", async () => {
|
|
516
|
+
const db = makeMockDB({ existingTables: ["some_table"] });
|
|
517
|
+
const diff = await diffSchema(db, []);
|
|
518
|
+
expect(diff.newTables).toHaveLength(0);
|
|
519
|
+
expect(diff.existingTables).toHaveLength(0);
|
|
520
|
+
});
|
|
521
|
+
});
|