@rebasepro/cli 0.30.0 → 0.31.0-canary.g59cd6fd
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 +8 -7
- package/dist/{agent-setup-0uyfC7VX.js → agent-setup-DqAcoDcn.js} +10 -5
- package/dist/{agent-setup-0uyfC7VX.js.map → agent-setup-DqAcoDcn.js.map} +1 -1
- package/dist/{api-keys-Dfw5-9s1.js → api-keys-eIUjMqWn.js} +8 -7
- package/dist/api-keys-eIUjMqWn.js.map +1 -0
- package/dist/{apps-MKQbgDtN.js → apps-DExO4PEl.js} +8 -7
- package/dist/apps-DExO4PEl.js.map +1 -0
- package/dist/{project-CasK56vN.js → args-CaCcrYE1.js} +2 -351
- package/dist/args-CaCcrYE1.js.map +1 -0
- package/dist/{atlas-dev-database-BODqdCWt.js → atlas-dev-database-DOCKk6ht.js} +2 -2
- package/dist/{atlas-dev-database-BODqdCWt.js.map → atlas-dev-database-DOCKk6ht.js.map} +1 -1
- package/dist/{auth-Bv0rTbQX.js → auth-D96QYgFR.js} +7 -6
- package/dist/{auth-Bv0rTbQX.js.map → auth-D96QYgFR.js.map} +1 -1
- package/dist/backend-guard-C0mVkXBw.js +162 -0
- package/dist/backend-guard-C0mVkXBw.js.map +1 -0
- package/dist/{branch-pointer-BQUF6lYa.js → branch-pointer-DMPyvZoK.js} +1 -1
- package/dist/{build-BuKTnec8.js → build-CA5R07tw.js} +29 -9
- package/dist/build-CA5R07tw.js.map +1 -0
- package/dist/{bundle-BAH4FCju.js → bundle-DgILeA5b.js} +112 -138
- package/dist/bundle-DgILeA5b.js.map +1 -0
- package/dist/bundle.d.ts +35 -12
- package/dist/cli.d.ts +2 -2
- package/dist/{cloud-Cj5ey3l_.js → cloud-CYMk92iG.js} +217 -104
- package/dist/cloud-CYMk92iG.js.map +1 -0
- package/dist/cms-directories-BK3vcswg.js +33 -0
- package/dist/cms-directories-BK3vcswg.js.map +1 -0
- package/dist/codemod/collections-to-tables/ast.d.ts +135 -0
- package/dist/codemod/collections-to-tables/backend.d.ts +38 -0
- package/dist/codemod/collections-to-tables/command.d.ts +35 -0
- package/dist/codemod/collections-to-tables/comments.d.ts +45 -0
- package/dist/codemod/collections-to-tables/customization.d.ts +47 -0
- package/dist/codemod/collections-to-tables/dynamic-props.d.ts +34 -0
- package/dist/codemod/collections-to-tables/export-changes.d.ts +83 -0
- package/dist/codemod/collections-to-tables/firestore.d.ts +11 -0
- package/dist/codemod/collections-to-tables/helper-hooks.d.ts +41 -0
- package/dist/codemod/collections-to-tables/hooks.d.ts +44 -0
- package/dist/codemod/collections-to-tables/journal.d.ts +10 -0
- package/dist/codemod/collections-to-tables/legacy-shims.d.ts +52 -0
- package/dist/codemod/collections-to-tables/load-legacy.d.ts +81 -0
- package/dist/codemod/collections-to-tables/migrate.d.ts +20 -0
- package/dist/codemod/collections-to-tables/modules.d.ts +127 -0
- package/dist/codemod/collections-to-tables/moved-imports.d.ts +70 -0
- package/dist/codemod/collections-to-tables/moved-symbols.generated.d.ts +12 -0
- package/dist/codemod/collections-to-tables/own.d.ts +10 -0
- package/dist/codemod/collections-to-tables/path-aliases.d.ts +26 -0
- package/dist/codemod/collections-to-tables/plan-context.d.ts +49 -0
- package/dist/codemod/collections-to-tables/print-js.d.ts +44 -0
- package/dist/codemod/collections-to-tables/project-files.d.ts +144 -0
- package/dist/codemod/collections-to-tables/repoint.d.ts +50 -0
- package/dist/codemod/collections-to-tables/row-hands.d.ts +7 -0
- package/dist/codemod/collections-to-tables/sdk-calls.d.ts +88 -0
- package/dist/codemod/collections-to-tables/skills-step.d.ts +13 -0
- package/dist/codemod/collections-to-tables/split-constants.d.ts +42 -0
- package/dist/codemod/collections-to-tables/storage-paths.d.ts +28 -0
- package/dist/codemod/collections-to-tables/types.d.ts +164 -0
- package/dist/codemod/collections-to-tables/verify.d.ts +27 -0
- package/dist/codemod/collections-to-tables/vocabulary.d.ts +40 -0
- package/dist/command-D5lhW_-B.js +9984 -0
- package/dist/command-D5lhW_-B.js.map +1 -0
- package/dist/commands/agent-setup.d.ts +6 -2
- package/dist/commands/cloud/auth.d.ts +2 -0
- package/dist/commands/cloud/context.d.ts +1 -1
- package/dist/commands/cloud/init.d.ts +2 -2
- package/dist/commands/cloud/login-flow.d.ts +30 -1
- package/dist/commands/console.d.ts +1 -2
- package/dist/commands/db.d.ts +5 -6
- package/dist/commands/dev.d.ts +18 -17
- package/dist/commands/doctor.d.ts +4 -5
- package/dist/commands/eject.d.ts +17 -13
- package/dist/commands/generate-view.d.ts +20 -9
- package/dist/commands/generate_sdk.d.ts +27 -27
- package/dist/commands/init.d.ts +21 -8
- package/dist/commands/migrate.d.ts +24 -0
- package/dist/commands/schema-reconcile.d.ts +1 -1
- package/dist/commands/skills.d.ts +8 -0
- package/dist/commands/verify-cms.d.ts +28 -0
- package/dist/commands/verify.d.ts +14 -9
- package/dist/{consent-BD7F29T3.js → consent-BXLIrMl8.js} +2 -2
- package/dist/{consent-BD7F29T3.js.map → consent-BXLIrMl8.js.map} +1 -1
- package/dist/{console-CdwIYOMV.js → console-C1d3LwB7.js} +14 -14
- package/dist/console-C1d3LwB7.js.map +1 -0
- package/dist/{context-AXdAh-q8.js → context--JwaHaZp.js} +6 -5
- package/dist/context--JwaHaZp.js.map +1 -0
- package/dist/{daemon-Cp7oNXth.js → daemon-w30PsdwV.js} +2 -2
- package/dist/{daemon-Cp7oNXth.js.map → daemon-w30PsdwV.js.map} +1 -1
- package/dist/{db-DBbKpjYX.js → db-DQZK9n9c.js} +52 -51
- package/dist/db-DQZK9n9c.js.map +1 -0
- package/dist/{derive-ae9UOoOB.js → derive-C3ezmY-p.js} +105 -133
- package/dist/derive-C3ezmY-p.js.map +1 -0
- package/dist/{dev-C93d4QIv.js → dev-PY5h4O6u.js} +142 -84
- package/dist/dev-PY5h4O6u.js.map +1 -0
- package/dist/dev-db/attver.d.ts +32 -0
- package/dist/dev-db/pull.d.ts +15 -1
- package/dist/{dev-preflight-Cxv3TiD1.js → dev-preflight-DjvcV6SK.js} +5 -5
- package/dist/dev-preflight-DjvcV6SK.js.map +1 -0
- package/dist/{dev-server-OJsUGZEB.js → dev-server-BLxCbQEP.js} +2 -2
- package/dist/{dev-server-OJsUGZEB.js.map → dev-server-BLxCbQEP.js.map} +1 -1
- package/dist/{doctor-BBPQUO2g.js → doctor-CnUu8kpM.js} +39 -62
- package/dist/doctor-CnUu8kpM.js.map +1 -0
- package/dist/doctor-environment.d.ts +6 -6
- package/dist/{eject-DABcDnPN.js → eject-Bhzd6hgb.js} +25 -16
- package/dist/eject-Bhzd6hgb.js.map +1 -0
- package/dist/{fold-static-BWzxNn06.js → fold-static-CKewnAPX.js} +5 -3
- package/dist/fold-static-CKewnAPX.js.map +1 -0
- package/dist/{generate-view-IFwCADvb.js → generate-view-CTOluXvH.js} +160 -89
- package/dist/generate-view-CTOluXvH.js.map +1 -0
- package/dist/{generate_sdk-DNmNuFuW.js → generate_sdk-De-aLC1L.js} +120 -137
- package/dist/generate_sdk-De-aLC1L.js.map +1 -0
- package/dist/import-schema-module-Df67TIWj.js +51 -0
- package/dist/import-schema-module-Df67TIWj.js.map +1 -0
- package/dist/index.es.js +64 -51
- package/dist/index.es.js.map +1 -1
- package/dist/{init-vL1DWOeC.js → init-Dtl-IcXf.js} +83 -80
- package/dist/init-Dtl-IcXf.js.map +1 -0
- package/dist/last-dev-database-Dc8cP01o.js +2 -0
- package/dist/{manifest-BtzDy7KQ.js → manifest-C3uLDrrJ.js} +115 -40
- package/dist/manifest-C3uLDrrJ.js.map +1 -0
- package/dist/manifest.d.ts +79 -24
- package/dist/migrate-VrKoi3nB.js +138 -0
- package/dist/migrate-VrKoi3nB.js.map +1 -0
- package/dist/{normalize-imports-Bd5Y4yLp.js → normalize-imports-DwxqEMYq.js} +3 -3
- package/dist/{normalize-imports-Bd5Y4yLp.js.map → normalize-imports-DwxqEMYq.js.map} +1 -1
- package/dist/path-flags-7O5uPBcQ.js +139 -0
- package/dist/path-flags-7O5uPBcQ.js.map +1 -0
- package/dist/{prepare-CTw9NEkh.js → prepare-Ccxspoj-.js} +4 -4
- package/dist/{prepare-CTw9NEkh.js.map → prepare-Ccxspoj-.js.map} +1 -1
- package/dist/project-CLcF5i8c.js +360 -0
- package/dist/project-CLcF5i8c.js.map +1 -0
- package/dist/project-schema-CsSOG2gE.js +30 -0
- package/dist/project-schema-CsSOG2gE.js.map +1 -0
- package/dist/{pull-DDMpsZ5r.js → pull-DRWqBZp5.js} +327 -4
- package/dist/pull-DRWqBZp5.js.map +1 -0
- package/dist/resolve-BY7bSFRT.js +2 -0
- package/dist/resources/derive.d.ts +19 -13
- package/dist/{resources-CPSC5Kcu.js → resources-Dpfs2y8P.js} +5 -4
- package/dist/{resources-CPSC5Kcu.js.map → resources-Dpfs2y8P.js.map} +1 -1
- package/dist/{schema-DtLPsXbT.js → schema-CdDjv5zI.js} +41 -39
- package/dist/schema-CdDjv5zI.js.map +1 -0
- package/dist/schema-dir-Cd1kvYbf.js +98 -0
- package/dist/schema-dir-Cd1kvYbf.js.map +1 -0
- package/dist/schema-reconcile-BAupXfkd.js +2 -0
- package/dist/schema-text-CpNrsuMe.js +73 -0
- package/dist/schema-text-CpNrsuMe.js.map +1 -0
- package/dist/{skills-CbwV6vw_.js → skills-CXjA9TWw.js} +54 -10
- package/dist/skills-CXjA9TWw.js.map +1 -0
- package/dist/{start-YOr3X5Zm.js → start-Bwbtt2W5.js} +7 -10
- package/dist/{start-YOr3X5Zm.js.map → start-Bwbtt2W5.js.map} +1 -1
- package/dist/{status-BREvtzJm.js → status-D7XCGHu2.js} +12 -12
- package/dist/status-D7XCGHu2.js.map +1 -0
- package/dist/{storage-CO9ouK76.js → storage-iTqj5-Av.js} +12 -11
- package/dist/storage-iTqj5-Av.js.map +1 -0
- package/dist/{telemetry-DwK5RQJl.js → telemetry-BP_1Cl9r.js} +4 -4
- package/dist/{telemetry-DwK5RQJl.js.map → telemetry-BP_1Cl9r.js.map} +1 -1
- package/dist/{telemetry-CgwJPVMO.js → telemetry-M3HjlyhZ.js} +2 -2
- package/dist/{telemetry-CgwJPVMO.js.map → telemetry-M3HjlyhZ.js.map} +1 -1
- package/dist/{upgrade-B7sVwL8S.js → upgrade-oZzJ13jM.js} +5 -4
- package/dist/{upgrade-B7sVwL8S.js.map → upgrade-oZzJ13jM.js.map} +1 -1
- package/dist/utils/backend-guard.d.ts +47 -0
- package/dist/utils/cms-directories.d.ts +6 -0
- package/dist/utils/dev-preflight.d.ts +2 -2
- package/dist/utils/import-schema-module.d.ts +16 -0
- package/dist/utils/path-flags.d.ts +35 -16
- package/dist/utils/project-schema.d.ts +40 -0
- package/dist/utils/project.d.ts +8 -2
- package/dist/utils/schema-dir.d.ts +32 -0
- package/dist/utils/schema-drift.d.ts +6 -0
- package/dist/utils/schema-text.d.ts +24 -0
- package/dist/verify-5p_vaUG2.js +1160 -0
- package/dist/verify-5p_vaUG2.js.map +1 -0
- package/package.json +11 -8
- package/runtime/dev-server.mjs +5 -1
- package/templates/eject/Dockerfile +1 -4
- package/templates/eject/backend/src/env.ts +1 -1
- package/templates/eject/backend/src/index.ts +53 -40
- package/templates/eject/docker-compose.custom.yml +1 -1
- package/templates/overlays/baas/README.md +39 -12
- package/templates/overlays/baas/ai-instructions.md +8 -8
- package/templates/overlays/baas/{config → backend}/storage.ts +3 -4
- package/templates/overlays/baas/backend/tsconfig.json +10 -12
- package/templates/overlays/baas/package.json +1 -2
- package/templates/overlays/baas/pnpm-workspace.yaml +0 -1
- package/templates/presets/blank/backend/schema/index.ts +19 -0
- package/templates/presets/blank/frontend/src/App.tsx +56 -0
- package/templates/presets/ecommerce/backend/schema/categories.ts +12 -0
- package/templates/presets/ecommerce/backend/schema/index.ts +23 -0
- package/templates/presets/ecommerce/backend/schema/orders.ts +13 -0
- package/templates/presets/ecommerce/backend/schema/products.ts +18 -0
- package/templates/presets/ecommerce/frontend/src/App.tsx +59 -0
- package/templates/presets/ecommerce/frontend/src/cms/categories.tsx +12 -0
- package/templates/presets/ecommerce/frontend/src/cms/orders.tsx +38 -0
- package/templates/presets/ecommerce/frontend/src/cms/products.tsx +27 -0
- package/templates/resource-graphs/blank.json +2 -2
- package/templates/resource-graphs/blog.json +5 -5
- package/templates/resource-graphs/ecommerce.json +5 -5
- package/templates/resource-graphs/headless.json +1 -1
- package/templates/template/.claude/hooks/post-edit-collection.sh +27 -23
- package/templates/template/.cursorrules +2 -2
- package/templates/template/.env.example +6 -17
- package/templates/template/.github/copilot-instructions.md +2 -2
- package/templates/template/.windsurfrules +2 -2
- package/templates/template/AGENTS.md +2 -2
- package/templates/template/CLAUDE.md +2 -2
- package/templates/template/README.md +47 -13
- package/templates/template/ai-instructions.md +15 -14
- package/templates/template/backend/functions/hello.ts +1 -1
- package/templates/template/backend/package.json +0 -2
- package/templates/template/{config → backend}/resources.ts +3 -3
- package/templates/template/backend/schema/authors.ts +11 -0
- package/templates/template/backend/schema/index.ts +29 -0
- package/templates/template/backend/schema/posts.ts +29 -0
- package/templates/template/backend/schema/tags.ts +9 -0
- package/templates/template/backend/schema/users.ts +32 -0
- package/templates/template/{config → backend}/storage.ts +4 -4
- package/templates/template/backend/tsconfig.json +15 -20
- package/templates/template/docker-compose.yml +3 -3
- package/templates/template/frontend/package.json +0 -2
- package/templates/template/frontend/src/App.tsx +10 -4
- package/templates/template/frontend/src/cms/authors.tsx +7 -0
- package/templates/template/frontend/src/cms/posts.tsx +27 -0
- package/templates/template/frontend/src/cms/tags.tsx +11 -0
- package/templates/template/frontend/src/cms/ui-config.json +3 -0
- package/templates/template/frontend/src/cms/users.tsx +54 -0
- package/templates/template/frontend/src/{virtual.d.ts → vite-env.d.ts} +0 -4
- package/templates/template/frontend/vite.config.ts +6 -2
- package/templates/template/gitignore +1 -1
- package/templates/template/package.json +1 -2
- package/templates/template/pnpm-workspace.yaml +0 -1
- package/templates/template/scripts/example.ts +3 -3
- package/templates/template/tsconfig.json +1 -1
- package/templates/views/AppView.tsx.tmpl +4 -4
- package/templates/views/EntityView.tsx.tmpl +3 -4
- package/dist/api-keys-Dfw5-9s1.js.map +0 -1
- package/dist/apps-MKQbgDtN.js.map +0 -1
- package/dist/build-BuKTnec8.js.map +0 -1
- package/dist/bundle-BAH4FCju.js.map +0 -1
- package/dist/cloud-Cj5ey3l_.js.map +0 -1
- package/dist/collection-drift-BKj_BoMq.js +0 -106
- package/dist/collection-drift-BKj_BoMq.js.map +0 -1
- package/dist/collections-dir-DlvDhime.js +0 -69
- package/dist/collections-dir-DlvDhime.js.map +0 -1
- package/dist/console-CdwIYOMV.js.map +0 -1
- package/dist/context-AXdAh-q8.js.map +0 -1
- package/dist/db-DBbKpjYX.js.map +0 -1
- package/dist/derive-ae9UOoOB.js.map +0 -1
- package/dist/dev-C93d4QIv.js.map +0 -1
- package/dist/dev-preflight-Cxv3TiD1.js.map +0 -1
- package/dist/doctor-BBPQUO2g.js.map +0 -1
- package/dist/eject-DABcDnPN.js.map +0 -1
- package/dist/fold-static-BWzxNn06.js.map +0 -1
- package/dist/generate-view-IFwCADvb.js.map +0 -1
- package/dist/generate_sdk-DNmNuFuW.js.map +0 -1
- package/dist/init-vL1DWOeC.js.map +0 -1
- package/dist/last-dev-database-DpW5dfoX.js +0 -2
- package/dist/manifest-BtzDy7KQ.js.map +0 -1
- package/dist/path-flags-DNvtEi2-.js +0 -92
- package/dist/path-flags-DNvtEi2-.js.map +0 -1
- package/dist/project-CasK56vN.js.map +0 -1
- package/dist/pull-DDMpsZ5r.js.map +0 -1
- package/dist/resolve-D647F1LA.js +0 -2
- package/dist/schema-DtLPsXbT.js.map +0 -1
- package/dist/schema-reconcile-DkArN9jF.js +0 -2
- package/dist/skills-CbwV6vw_.js.map +0 -1
- package/dist/status-BREvtzJm.js.map +0 -1
- package/dist/storage-CO9ouK76.js.map +0 -1
- package/dist/utils/collection-drift.d.ts +0 -27
- package/dist/utils/collections-dir.d.ts +0 -14
- package/dist/verify-Y3rWSgfA.js +0 -730
- package/dist/verify-Y3rWSgfA.js.map +0 -1
- package/templates/overlays/baas/config/index.ts +0 -24
- package/templates/overlays/baas/config/package.json +0 -30
- package/templates/template/config/cms.d.ts +0 -15
- package/templates/template/config/collections/authors.ts +0 -47
- package/templates/template/config/collections/index.ts +0 -44
- package/templates/template/config/collections/posts.ts +0 -94
- package/templates/template/config/collections/presets/blank/index.ts +0 -5
- package/templates/template/config/collections/presets/ecommerce/categories.ts +0 -42
- package/templates/template/config/collections/presets/ecommerce/index.ts +0 -31
- package/templates/template/config/collections/presets/ecommerce/orders.ts +0 -78
- package/templates/template/config/collections/presets/ecommerce/products.ts +0 -73
- package/templates/template/config/collections/tags.ts +0 -27
- package/templates/template/config/collections/users.ts +0 -149
- package/templates/template/config/frontend-assets.d.ts +0 -17
- package/templates/template/config/index.ts +0 -12
- package/templates/template/config/package.json +0 -30
- package/templates/template/config/tsconfig.json +0 -35
- /package/templates/eject/{config → backend}/resources.ts +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { a as wantsHelp, n as parseCommandArgs } from "./args-CaCcrYE1.js";
|
|
2
|
+
import { i as failAsJson, p as requireProjectRoot } from "./project-CLcF5i8c.js";
|
|
3
|
+
import { _ as findBackendApp, b as loadManifest, l as ManifestError } from "./manifest-C3uLDrrJ.js";
|
|
4
|
+
import { a as projectResourceGraph, l as writeResourceGraphFile, n as deriveOptionsFor, o as readResourceGraphFile, r as deriveResourceGraph, s as serializeResourceGraph, t as RESOURCE_GRAPH_FILENAME } from "./derive-C3ezmY-p.js";
|
|
4
5
|
import chalk from "chalk";
|
|
5
6
|
import path from "path";
|
|
6
7
|
import { declaredSubscriptions } from "@rebasepro/types";
|
|
@@ -179,4 +180,4 @@ async function resourcesCommand(rawArgs) {
|
|
|
179
180
|
//#endregion
|
|
180
181
|
export { resourcesCommand };
|
|
181
182
|
|
|
182
|
-
//# sourceMappingURL=resources-
|
|
183
|
+
//# sourceMappingURL=resources-Dpfs2y8P.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resources-CPSC5Kcu.js","names":[],"sources":["../src/commands/resources.ts"],"sourcesContent":["/**\n * CLI command: rebase resources\n *\n * Shows what a project declares, and keeps the committed graph honest.\n *\n * The graph is generated, so it can drift the moment somebody adds a bucket and\n * does not regenerate. Drift here is not cosmetic: the committed file is what a\n * host reads to decide what to provision, so a stale one means the console\n * offers a project one set of resources while the runtime asks for another.\n * `--check` is the gate that makes that impossible to land.\n */\nimport chalk from \"chalk\";\nimport path from \"path\";\nimport { failAsJson, requireProjectRoot } from \"../utils/project\";\nimport { findBackendApp, loadManifest, ManifestError } from \"../manifest\";\nimport { parseCommandArgs, wantsHelp } from \"../utils/args\";\nimport {\n RESOURCE_GRAPH_FILENAME,\n deriveOptionsFor, deriveResourceGraph,\n projectResourceGraph,\n readResourceGraphFile,\n serializeResourceGraph,\n writeResourceGraphFile,\n type ProjectedResource\n} from \"../resources/derive\";\nimport { declaredSubscriptions, type RebaseBackendAppConfig } from \"@rebasepro/types\";\n\nfunction usage(): void {\n console.log(`\n${chalk.bold(\"rebase resources\")} — what this project needs\n\n ${chalk.blue(\"rebase resources\")} List them, declared and implicit\n ${chalk.blue(\"rebase resources --write\")} Regenerate ${RESOURCE_GRAPH_FILENAME}\n ${chalk.blue(\"rebase resources --check\")} Fail if the committed graph is stale\n ${chalk.blue(\"rebase resources --json\")} The same set, machine-readable; with --check or --write,\n their result too (a failed check is an error envelope, exit 1)\n\nA resource is declared in config code — ${chalk.gray('database(\"analytics\"), bucket(\"media\"), topic(\"signups\")')} —\nand never in ${RESOURCE_GRAPH_FILENAME}, which is generated from those declarations so a host\ncan read what a project needs without building it. A backend also has a default\ndatabase and a default storage source nobody declared; both are listed here,\nmarked ${chalk.gray(\"implicit\")}, and neither is written to that file — the host supplies them.\n`);\n}\n\n/**\n * Render the projection the way somebody reads it: grouped by kind, key first.\n *\n * The projection, not the raw graph. `rebase status` has always included the\n * implicit default database and bucket and this listing did not, so the two\n * commands answered \"what does this project need\" differently on the same stock\n * scaffold. There is no \"no resources declared\" case any more: a backend has a\n * database and a storage source whether or not anyone wrote them down.\n */\nfunction print(resources: ProjectedResource[]): void {\n // Infrastructure first, then code: what needs binding is what a reader\n // is here to check.\n const order = [\"database\", \"bucket\", \"topic\", \"queue\", \"cron\", \"function\"];\n const kinds = [...new Set(resources.map(r => r.kind))]\n .sort((a, b) => (order.indexOf(a) === -1 ? 99 : order.indexOf(a)) - (order.indexOf(b) === -1 ? 99 : order.indexOf(b)));\n for (const kind of kinds) {\n console.log(`\\n ${chalk.bold(kind)}`);\n for (const r of resources.filter(x => x.kind === kind)) {\n const bits: string[] = [];\n if (kind === \"cron\") {\n bits.push(chalk.cyan(String(r.options.schedule)));\n bits.push(chalk.gray(r.options.timezone ? String(r.options.timezone) : \"local time\"));\n } else if (kind === \"function\") {\n bits.push(chalk.gray(String(r.options.file ?? \"\")));\n if (r.options.portable === false) bits.push(chalk.yellow(\"node-only\"));\n } else {\n bits.push(chalk.gray(r.engine));\n if (r.transport !== \"server\") bits.push(chalk.yellow(r.transport));\n for (const [k, v] of Object.entries(r.options)) bits.push(chalk.gray(`${k}=${String(v)}`));\n }\n // Marked, not hidden: a declared resource is recorded in\n // `rebase.resources.json` for a host to provision, and an implicit\n // one is a default the runtime supplies regardless.\n if (r.implicit) bits.push(chalk.gray(\"implicit\"));\n console.log(` ${r.key.padEnd(24)} ${bits.join(\" · \")}`);\n if (kind === \"topic\") {\n for (const sub of declaredSubscriptions(r.key)) {\n console.log(` ${chalk.gray(\"→\")} ${sub.name}`);\n }\n }\n if (r.usedBy && r.usedBy.length > 0) {\n console.log(` ${chalk.gray(\"used by\")} ${chalk.gray(r.usedBy.join(\", \"))}`);\n }\n }\n }\n console.log(\"\");\n}\n\nexport async function resourcesCommand(rawArgs: string[]): Promise<void> {\n if (wantsHelp(rawArgs)) return usage();\n\n const { flags } = parseCommandArgs({\n spec: {\n \"--write\": Boolean,\n \"--check\": Boolean,\n \"--json\": Boolean\n },\n rawArgs,\n commandWords: 1,\n command: \"resources\",\n maxPositionals: 0\n });\n\n const projectRoot = requireProjectRoot();\n\n // Every exit below has a `--json` arm, for the reason in `failAsJson`:\n // `--json` is a promise about stdout, and a promise kept on one exit of a\n // command and broken on the next is not one.\n const asJson = Boolean(flags[\"--json\"]);\n\n let backendApp: RebaseBackendAppConfig;\n try {\n const loaded = loadManifest(projectRoot);\n const backend = findBackendApp(loaded.manifest);\n if (!backend) {\n if (asJson) {\n failAsJson(\n \"This project declares no backend app, so it declares no resources.\",\n \"no_backend_app\",\n \"Add a backend app to rebase.json, or run `rebase apps init`.\"\n );\n }\n console.error(chalk.red(\"This project declares no backend app, so it declares no resources.\"));\n process.exitCode = 1;\n return;\n }\n backendApp = backend.app;\n } catch (err) {\n if (err instanceof ManifestError) {\n if (asJson) {\n failAsJson(err.message, \"manifest_invalid\", \"Fix rebase.json, then run this again.\",\n err.issues.map(issue => ({ path: issue.path, message: issue.message })));\n }\n console.error(chalk.red(err.message));\n for (const issue of err.issues) console.error(` ${chalk.gray(issue.path)} ${issue.message}`);\n process.exitCode = 1;\n return;\n }\n throw err;\n }\n\n const { graph, issues } = await deriveResourceGraph(deriveOptionsFor(projectRoot, backendApp));\n\n if (issues.length > 0) {\n if (asJson) {\n failAsJson(\n `${issues.length} problem(s) in the declared resources.`,\n \"resource_declaration_invalid\",\n \"Fix the declarations the issues name, then run this again.\",\n issues.map(issue => ({ path: issue.path, message: issue.message }))\n );\n }\n console.error(chalk.red(`\\n✗ ${issues.length} problem(s) in the declared resources:\\n`));\n for (const issue of issues) console.error(` ${chalk.bold(issue.path)} ${issue.message}`);\n console.error(\"\");\n process.exitCode = 1;\n return;\n }\n\n // The projection, so this and `rebase status --json` describe the same\n // set. `version` is kept so a reader of either can tell them apart from a\n // future shape. `--check` and `--write` add what they did to it: `--json`\n // changes how the answer is printed, never which question is answered — it\n // used to return here, so `--check --json` exited 0 on any drift and\n // `--write --json` wrote nothing.\n const projection = () => ({ version: graph.version, resources: projectResourceGraph(graph) });\n\n if (flags[\"--check\"]) {\n const committed = readResourceGraphFile(projectRoot);\n const expected = serializeResourceGraph(graph);\n // Declaring nothing and having no file is a consistent state, not a\n // stale one. The file records declarations; a project with none has\n // nothing to record, and its default database and bucket are implicit\n // by design — that is the overwhelmingly common project and it must not\n // be required to commit an empty file saying so.\n //\n // This mattered the moment the check was put in a gate: it would have\n // failed this repository's own reference app, which declares nothing,\n // and every scaffolded project until someone declared a second bucket.\n const status = committed === expected\n ? \"current\"\n : committed === null && graph.resources.length === 0 ? \"nothing-declared\" : null;\n\n if (status !== null) {\n if (asJson) {\n console.log(JSON.stringify({ ...projection(), check: { file: RESOURCE_GRAPH_FILENAME, status } }, null, 2));\n return;\n }\n console.log(status === \"current\"\n ? chalk.green(`✓ ${RESOURCE_GRAPH_FILENAME} matches the declarations.`)\n : chalk.gray(\"✓ Nothing declared, so there is nothing to record.\"));\n return;\n }\n\n const state = committed === null ? \"missing\" : \"stale\";\n if (asJson) {\n failAsJson(\n `${RESOURCE_GRAPH_FILENAME} is ${state}.`,\n `resource_graph_${state}`,\n \"Regenerate it with `rebase resources --write`, and commit it.\"\n );\n }\n console.error(chalk.red(`\\n✗ ${RESOURCE_GRAPH_FILENAME} is ${state}.\\n`));\n console.error(\n \" A host reads this file to decide what to provision, so a stale one means the\\n\" +\n \" console offers one set of resources while the runtime asks for another.\\n\"\n );\n console.error(` Regenerate it: ${chalk.blue(\"rebase resources --write\")}\\n`);\n process.exitCode = 1;\n return;\n }\n\n if (flags[\"--write\"]) {\n const { changed, file } = writeResourceGraphFile(projectRoot, graph);\n const relative = path.relative(projectRoot, file);\n if (asJson) {\n console.log(JSON.stringify({ ...projection(), written: { file: relative, changed } }, null, 2));\n return;\n }\n console.log(changed\n ? chalk.green(`✓ Wrote ${relative}`)\n : chalk.gray(`${relative} already matched the declarations.`));\n return;\n }\n\n if (asJson) {\n console.log(JSON.stringify(projection(), null, 2));\n return;\n }\n\n print(projectRes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AAC,CAAC;IAC1G;GACJ;GACA,QAAQ,IAAI,WAAW,YACjB,MAAM,MAAM,KAAK,wBAAwB,2BAA2B,IACpE,MAAM,KAAK,oDAAoD,CAAC;GACtE;EACJ;EAEA,MAAM,QAAQ,cAAc,OAAO,YAAY;EAC/C,IAAI,QACA,WACI,GAAG,wBAAwB,MAAM,MAAM,IACvC,kBAAkB,SAClB,+DACJ;EAEJ,QAAQ,MAAM,MAAM,IAAI,OAAO,wBAAwB,MAAM,MAAM,IAAI,CAAC;EACxE,QAAQ,MACJ,6JAEJ;EACA,QAAQ,MAAM,qBAAqB,MAAM,KAAK,0BAA0B,EAAE,GAAG;EAC7E,QAAQ,WAAW;EACnB;CACJ;CAEA,IAAI,MAAM,YAAY;EAClB,MAAM,EAAE,SAAS,SAAS,uBAAuB,aAAa,KAAK;EACnE,MAAM,WAAW,KAAK,SAAS,aAAa,IAAI;EAChD,IAAI,QAAQ;GACR,QAAQ,IAAI,KAAK,UAAU;IAAE,GAAG,WAAW;IAAG,SAAS;KAAE,MAAM;KAAU;IAAQ;GAAE,GAAG,MAAM,CAAC,CAAC;GAC9F;EACJ;EACA,QAAQ,IAAI,UACN,MAAM,MAAM,WAAW,UAAU,IACjC,MAAM,KAAK,GAAG,SAAS,mCAAmC,CAAC;EACjE;CACJ;CAEA,IAAI,QAAQ;EACR,QAAQ,IAAI,KAAK,UAAU,WAAW,GAAG,MAAM,CAAC,CAAC;EACjD;CACJ;CAEA,MAAM,qBAAqB,KAAK,CAAC;AACrC"}
|
|
1
|
+
{"version":3,"file":"resources-Dpfs2y8P.js","names":[],"sources":["../src/commands/resources.ts"],"sourcesContent":["/**\n * CLI command: rebase resources\n *\n * Shows what a project declares, and keeps the committed graph honest.\n *\n * The graph is generated, so it can drift the moment somebody adds a bucket and\n * does not regenerate. Drift here is not cosmetic: the committed file is what a\n * host reads to decide what to provision, so a stale one means the console\n * offers a project one set of resources while the runtime asks for another.\n * `--check` is the gate that makes that impossible to land.\n */\nimport chalk from \"chalk\";\nimport path from \"path\";\nimport { failAsJson, requireProjectRoot } from \"../utils/project\";\nimport { findBackendApp, loadManifest, ManifestError } from \"../manifest\";\nimport { parseCommandArgs, wantsHelp } from \"../utils/args\";\nimport {\n RESOURCE_GRAPH_FILENAME,\n deriveOptionsFor, deriveResourceGraph,\n projectResourceGraph,\n readResourceGraphFile,\n serializeResourceGraph,\n writeResourceGraphFile,\n type ProjectedResource\n} from \"../resources/derive\";\nimport { declaredSubscriptions, type RebaseBackendAppConfig } from \"@rebasepro/types\";\n\nfunction usage(): void {\n console.log(`\n${chalk.bold(\"rebase resources\")} — what this project needs\n\n ${chalk.blue(\"rebase resources\")} List them, declared and implicit\n ${chalk.blue(\"rebase resources --write\")} Regenerate ${RESOURCE_GRAPH_FILENAME}\n ${chalk.blue(\"rebase resources --check\")} Fail if the committed graph is stale\n ${chalk.blue(\"rebase resources --json\")} The same set, machine-readable; with --check or --write,\n their result too (a failed check is an error envelope, exit 1)\n\nA resource is declared in config code — ${chalk.gray('database(\"analytics\"), bucket(\"media\"), topic(\"signups\")')} —\nand never in ${RESOURCE_GRAPH_FILENAME}, which is generated from those declarations so a host\ncan read what a project needs without building it. A backend also has a default\ndatabase and a default storage source nobody declared; both are listed here,\nmarked ${chalk.gray(\"implicit\")}, and neither is written to that file — the host supplies them.\n`);\n}\n\n/**\n * Render the projection the way somebody reads it: grouped by kind, key first.\n *\n * The projection, not the raw graph. `rebase status` has always included the\n * implicit default database and bucket and this listing did not, so the two\n * commands answered \"what does this project need\" differently on the same stock\n * scaffold. There is no \"no resources declared\" case any more: a backend has a\n * database and a storage source whether or not anyone wrote them down.\n */\nfunction print(resources: ProjectedResource[]): void {\n // Infrastructure first, then code: what needs binding is what a reader\n // is here to check.\n const order = [\"database\", \"bucket\", \"topic\", \"queue\", \"cron\", \"function\"];\n const kinds = [...new Set(resources.map(r => r.kind))]\n .sort((a, b) => (order.indexOf(a) === -1 ? 99 : order.indexOf(a)) - (order.indexOf(b) === -1 ? 99 : order.indexOf(b)));\n for (const kind of kinds) {\n console.log(`\\n ${chalk.bold(kind)}`);\n for (const r of resources.filter(x => x.kind === kind)) {\n const bits: string[] = [];\n if (kind === \"cron\") {\n bits.push(chalk.cyan(String(r.options.schedule)));\n bits.push(chalk.gray(r.options.timezone ? String(r.options.timezone) : \"local time\"));\n } else if (kind === \"function\") {\n bits.push(chalk.gray(String(r.options.file ?? \"\")));\n if (r.options.portable === false) bits.push(chalk.yellow(\"node-only\"));\n } else {\n bits.push(chalk.gray(r.engine));\n if (r.transport !== \"server\") bits.push(chalk.yellow(r.transport));\n for (const [k, v] of Object.entries(r.options)) bits.push(chalk.gray(`${k}=${String(v)}`));\n }\n // Marked, not hidden: a declared resource is recorded in\n // `rebase.resources.json` for a host to provision, and an implicit\n // one is a default the runtime supplies regardless.\n if (r.implicit) bits.push(chalk.gray(\"implicit\"));\n console.log(` ${r.key.padEnd(24)} ${bits.join(\" · \")}`);\n if (kind === \"topic\") {\n for (const sub of declaredSubscriptions(r.key)) {\n console.log(` ${chalk.gray(\"→\")} ${sub.name}`);\n }\n }\n if (r.usedBy && r.usedBy.length > 0) {\n console.log(` ${chalk.gray(\"used by\")} ${chalk.gray(r.usedBy.join(\", \"))}`);\n }\n }\n }\n console.log(\"\");\n}\n\nexport async function resourcesCommand(rawArgs: string[]): Promise<void> {\n if (wantsHelp(rawArgs)) return usage();\n\n const { flags } = parseCommandArgs({\n spec: {\n \"--write\": Boolean,\n \"--check\": Boolean,\n \"--json\": Boolean\n },\n rawArgs,\n commandWords: 1,\n command: \"resources\",\n maxPositionals: 0\n });\n\n const projectRoot = requireProjectRoot();\n\n // Every exit below has a `--json` arm, for the reason in `failAsJson`:\n // `--json` is a promise about stdout, and a promise kept on one exit of a\n // command and broken on the next is not one.\n const asJson = Boolean(flags[\"--json\"]);\n\n let backendApp: RebaseBackendAppConfig;\n try {\n const loaded = loadManifest(projectRoot);\n const backend = findBackendApp(loaded.manifest);\n if (!backend) {\n if (asJson) {\n failAsJson(\n \"This project declares no backend app, so it declares no resources.\",\n \"no_backend_app\",\n \"Add a backend app to rebase.json, or run `rebase apps init`.\"\n );\n }\n console.error(chalk.red(\"This project declares no backend app, so it declares no resources.\"));\n process.exitCode = 1;\n return;\n }\n backendApp = backend.app;\n } catch (err) {\n if (err instanceof ManifestError) {\n if (asJson) {\n failAsJson(err.message, \"manifest_invalid\", \"Fix rebase.json, then run this again.\",\n err.issues.map(issue => ({ path: issue.path, message: issue.message })));\n }\n console.error(chalk.red(err.message));\n for (const issue of err.issues) console.error(` ${chalk.gray(issue.path)} ${issue.message}`);\n process.exitCode = 1;\n return;\n }\n throw err;\n }\n\n const { graph, issues } = await deriveResourceGraph(deriveOptionsFor(projectRoot, backendApp));\n\n if (issues.length > 0) {\n if (asJson) {\n failAsJson(\n `${issues.length} problem(s) in the declared resources.`,\n \"resource_declaration_invalid\",\n \"Fix the declarations the issues name, then run this again.\",\n issues.map(issue => ({ path: issue.path, message: issue.message }))\n );\n }\n console.error(chalk.red(`\\n✗ ${issues.length} problem(s) in the declared resources:\\n`));\n for (const issue of issues) console.error(` ${chalk.bold(issue.path)} ${issue.message}`);\n console.error(\"\");\n process.exitCode = 1;\n return;\n }\n\n // The projection, so this and `rebase status --json` describe the same\n // set. `version` is kept so a reader of either can tell them apart from a\n // future shape. `--check` and `--write` add what they did to it: `--json`\n // changes how the answer is printed, never which question is answered — it\n // used to return here, so `--check --json` exited 0 on any drift and\n // `--write --json` wrote nothing.\n const projection = () => ({ version: graph.version, resources: projectResourceGraph(graph) });\n\n if (flags[\"--check\"]) {\n const committed = readResourceGraphFile(projectRoot);\n const expected = serializeResourceGraph(graph);\n // Declaring nothing and having no file is a consistent state, not a\n // stale one. The file records declarations; a project with none has\n // nothing to record, and its default database and bucket are implicit\n // by design — that is the overwhelmingly common project and it must not\n // be required to commit an empty file saying so.\n //\n // This mattered the moment the check was put in a gate: it would have\n // failed this repository's own reference app, which declares nothing,\n // and every scaffolded project until someone declared a second bucket.\n const status = committed === expected\n ? \"current\"\n : committed === null && graph.resources.length === 0 ? \"nothing-declared\" : null;\n\n if (status !== null) {\n if (asJson) {\n console.log(JSON.stringify({ ...projection(), check: { file: RESOURCE_GRAPH_FILENAME, status } }, null, 2));\n return;\n }\n console.log(status === \"current\"\n ? chalk.green(`✓ ${RESOURCE_GRAPH_FILENAME} matches the declarations.`)\n : chalk.gray(\"✓ Nothing declared, so there is nothing to record.\"));\n return;\n }\n\n const state = committed === null ? \"missing\" : \"stale\";\n if (asJson) {\n failAsJson(\n `${RESOURCE_GRAPH_FILENAME} is ${state}.`,\n `resource_graph_${state}`,\n \"Regenerate it with `rebase resources --write`, and commit it.\"\n );\n }\n console.error(chalk.red(`\\n✗ ${RESOURCE_GRAPH_FILENAME} is ${state}.\\n`));\n console.error(\n \" A host reads this file to decide what to provision, so a stale one means the\\n\" +\n \" console offers one set of resources while the runtime asks for another.\\n\"\n );\n console.error(` Regenerate it: ${chalk.blue(\"rebase resources --write\")}\\n`);\n process.exitCode = 1;\n return;\n }\n\n if (flags[\"--write\"]) {\n const { changed, file } = writeResourceGraphFile(projectRoot, graph);\n const relative = path.relative(projectRoot, file);\n if (asJson) {\n console.log(JSON.stringify({ ...projection(), written: { file: relative, changed } }, null, 2));\n return;\n }\n console.log(changed\n ? chalk.green(`✓ Wrote ${relative}`)\n : chalk.gray(`${relative} already matched the declarations.`));\n return;\n }\n\n if (asJson) {\n console.log(JSON.stringify(projection(), null, 2));\n return;\n }\n\n print(projectResourceGraph(graph));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA2BA,SAAS,QAAc;CACnB,QAAQ,IAAI;EACd,MAAM,KAAK,kBAAkB,EAAE;;IAE7B,MAAM,KAAK,kBAAkB,EAAE;IAC/B,MAAM,KAAK,0BAA0B,EAAE,iBAAiB,wBAAwB;IAChF,MAAM,KAAK,0BAA0B,EAAE;IACvC,MAAM,KAAK,yBAAyB,EAAE;;;0CAGA,MAAM,KAAK,gEAA0D,EAAE;eAClG,wBA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CAAC;EACxE,QAAQ,MACJ,6JAEJ;EACA,QAAQ,MAAM,qBAAqB,MAAM,KAAK,0BAA0B,EAAE,GAAG;EAC7E,QAAQ,WAAW;EACnB;CACJ;CAEA,IAAI,MAAM,YAAY;EAClB,MAAM,EAAE,SAAS,SAAS,uBAAuB,aAAa,KAAK;EACnE,MAAM,WAAW,KAAK,SAAS,aAAa,IAAI;EAChD,IAAI,QAAQ;GACR,QAAQ,IAAI,KAAK,UAAU;IAAE,GAAG,WAAW;IAAG,SAAS;KAAE,MAAM;KAAU;IAAQ;GAAE,GAAG,MAAM,CAAC,CAAC;GAC9F;EACJ;EACA,QAAQ,IAAI,UACN,MAAM,MAAM,WAAW,UAAU,IACjC,MAAM,KAAK,GAAG,SAAS,mCAAmC,CAAC;EACjE;CACJ;CAEA,IAAI,QAAQ;EACR,QAAQ,IAAI,KAAK,UAAU,WAAW,GAAG,MAAM,CAAC,CAAC;EACjD;CACJ;CAEA,MAAM,qBAAqB,KAAK,CAAC;AACrC"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { i as recordEvent } from "./telemetry-
|
|
2
|
-
import {
|
|
1
|
+
import { i as recordEvent } from "./telemetry-M3HjlyhZ.js";
|
|
2
|
+
import { a as wantsHelp, s as unknownCommand, t as UsageError } from "./args-CaCcrYE1.js";
|
|
3
|
+
import { d as readEnvFile, f as requireBackendDir, h as resolvePluginCliScript, l as getActiveBackendPlugin, o as findEnvFile, p as requireProjectRoot, r as exitDependenciesNotInstalled } from "./project-CLcF5i8c.js";
|
|
4
|
+
import { r as schemaDirArgs } from "./schema-dir-Cd1kvYbf.js";
|
|
5
|
+
import { a as refuseRemovedCollectionsFlag, i as refuseMissingSchemaDir, n as SCHEMA_DIR_FLAG_HELP } from "./path-flags-7O5uPBcQ.js";
|
|
3
6
|
import { t as cliUserAgent } from "./version-Buyyo1ut.js";
|
|
4
|
-
import { i as requireBackendUrl, r as describeFailure } from "./api-keys-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { DEV_DATABASE_KIND_ENV, devDatabaseKind, managedNotices, prepareDatabaseEnv } from "./prepare-CTw9NEkh.js";
|
|
8
|
-
import { absolutizeLocalPathArgs, ensureDockerDatabase, n as argsFromCommand, spawnDriverCli, t as reportSpawnFailure } from "./db-DBbKpjYX.js";
|
|
7
|
+
import { i as requireBackendUrl, r as describeFailure } from "./api-keys-eIUjMqWn.js";
|
|
8
|
+
import { DEV_DATABASE_KIND_ENV, devDatabaseKind, managedNotices, prepareDatabaseEnv } from "./prepare-Ccxspoj-.js";
|
|
9
|
+
import { absolutizeLocalPathArgs, ensureDockerDatabase, n as argsFromCommand, spawnDriverCli, t as reportSpawnFailure } from "./db-DQZK9n9c.js";
|
|
9
10
|
import chalk from "chalk";
|
|
10
11
|
import arg from "arg";
|
|
11
12
|
import { RebaseApiError } from "@rebasepro/client";
|
|
@@ -15,18 +16,18 @@ import readline from "node:readline/promises";
|
|
|
15
16
|
* CLI command: rebase schema reconcile
|
|
16
17
|
*
|
|
17
18
|
* The reviewed step for what boot will not do. Boot only ever adds, so a
|
|
18
|
-
*
|
|
19
|
-
* leaves
|
|
19
|
+
* column made nullable keeps its NOT NULL, and a column removed from a table
|
|
20
|
+
* leaves it behind, with its data, and blocking inserts if it was
|
|
20
21
|
* required. This asks the running backend for the plan that fixes both, prints
|
|
21
22
|
* it, and applies it only once confirmed.
|
|
22
23
|
*
|
|
23
24
|
* Through the backend rather than a database URL, because on Rebase Cloud the
|
|
24
25
|
* backend is the one thing that can reach the database — and because it plans
|
|
25
|
-
* against the
|
|
26
|
+
* against the tables it actually runs, not the ones in this checkout.
|
|
26
27
|
* Columns are dropped only when named with `--drop`; the confirmation sends
|
|
27
28
|
* the plan's digest, so the server runs exactly the statements printed here.
|
|
28
29
|
*/
|
|
29
|
-
var RECONCILE_USAGE = "rebase schema reconcile [--drop <
|
|
30
|
+
var RECONCILE_USAGE = "rebase schema reconcile [--drop <table>.<column>]... [--yes]";
|
|
30
31
|
function parseReconcileArgs(rawArgs) {
|
|
31
32
|
const flags = arg({
|
|
32
33
|
"--drop": [String],
|
|
@@ -43,7 +44,7 @@ function parseReconcileArgs(rawArgs) {
|
|
|
43
44
|
function describeReconcilePlan(plan) {
|
|
44
45
|
const lines = [];
|
|
45
46
|
for (const r of plan.relaxed) {
|
|
46
|
-
const why = r.undeclared ? `
|
|
47
|
+
const why = r.undeclared ? `"${r.collection}" does not declare it, and every insert fails on it; its data stays` : `nullable in "${r.collection}", NOT NULL in the database`;
|
|
47
48
|
lines.push(` ${chalk.cyan("relax")} ${r.table}.${r.column} ${chalk.gray(why)}`);
|
|
48
49
|
}
|
|
49
50
|
for (const d of plan.dropped) {
|
|
@@ -52,7 +53,7 @@ function describeReconcilePlan(plan) {
|
|
|
52
53
|
}
|
|
53
54
|
const kept = plan.undeclared.filter((u) => !plan.dropped.some((d) => d.table === u.table && d.column === u.column) && !plan.relaxed.some((r) => r.undeclared && r.table === u.table && r.column === u.column));
|
|
54
55
|
for (const u of kept) {
|
|
55
|
-
const note = u.blocksInserts ? chalk.yellow("NOT NULL with no default: every insert fails until it is dropped or relaxed") : chalk.gray("no
|
|
56
|
+
const note = u.blocksInserts ? chalk.yellow("NOT NULL with no default: every insert fails until it is dropped or relaxed") : chalk.gray("no table declares it; kept");
|
|
56
57
|
lines.push(` ${chalk.gray("keep")} ${u.table}.${u.column} ${note}`);
|
|
57
58
|
}
|
|
58
59
|
return lines;
|
|
@@ -123,8 +124,8 @@ async function schemaReconcileCommand(rawArgs) {
|
|
|
123
124
|
for (const problem of plan.problems) console.error(chalk.red(` • ${problem}`));
|
|
124
125
|
process.exit(1);
|
|
125
126
|
}
|
|
126
|
-
if (plan.statements.length === 0) console.log(chalk.green("✓ Nothing to do: the database already matches what the
|
|
127
|
-
if (plan.undeclared.length > plan.dropped.length) console.log(chalk.gray(" To drop a column no
|
|
127
|
+
if (plan.statements.length === 0) console.log(chalk.green("✓ Nothing to do: the database already matches what the tables declare."));
|
|
128
|
+
if (plan.undeclared.length > plan.dropped.length) console.log(chalk.gray(" To drop a column no table declares, name it: --drop <table>.<column>"));
|
|
128
129
|
if (plan.statements.length === 0) return;
|
|
129
130
|
console.log(chalk.bold("\nStatements"));
|
|
130
131
|
for (const statement of plan.statements) console.log(` ${statement}`);
|
|
@@ -153,7 +154,7 @@ async function schemaReconcileCommand(rawArgs) {
|
|
|
153
154
|
console.log(chalk.green(`✓ Applied ${result.applied.length} statement(s).`));
|
|
154
155
|
} catch (error) {
|
|
155
156
|
if (error instanceof RebaseApiError && error.code === "SCHEMA_RECONCILE_STALE") {
|
|
156
|
-
console.error(chalk.red("✗ Not applied: the database or the
|
|
157
|
+
console.error(chalk.red("✗ Not applied: the database or the tables changed since this plan was made. Run it again to review the new plan."));
|
|
157
158
|
process.exit(1);
|
|
158
159
|
}
|
|
159
160
|
fail("Failed to apply the reconcile", error, backend.baseUrl);
|
|
@@ -171,8 +172,7 @@ async function schemaReconcileCommand(rawArgs) {
|
|
|
171
172
|
*/
|
|
172
173
|
function schemaDriverArgs(rawArgs, cwd) {
|
|
173
174
|
return absolutizeLocalPathArgs(argsFromCommand(rawArgs, "schema"), cwd, [
|
|
174
|
-
"--
|
|
175
|
-
"-c",
|
|
175
|
+
"--schema-dir",
|
|
176
176
|
"--output",
|
|
177
177
|
"-o",
|
|
178
178
|
"--out"
|
|
@@ -184,10 +184,11 @@ async function schemaCommand(subcommand, rawArgs) {
|
|
|
184
184
|
return;
|
|
185
185
|
}
|
|
186
186
|
if (!SCHEMA_ACTION_HELP[subcommand]) unknownCommand(subcommand, Object.keys(SCHEMA_ACTION_HELP), "schema");
|
|
187
|
+
refuseRemovedCollectionsFlag(rawArgs.slice(2), `schema ${subcommand}`);
|
|
187
188
|
const projectRoot = requireProjectRoot();
|
|
188
189
|
if (subcommand === "reconcile") {
|
|
189
190
|
recordEvent("cli.schema", { subcommand }, { projectRoot });
|
|
190
|
-
const { schemaReconcileCommand } = await import("./schema-reconcile-
|
|
191
|
+
const { schemaReconcileCommand } = await import("./schema-reconcile-BAupXfkd.js");
|
|
191
192
|
await schemaReconcileCommand(rawArgs);
|
|
192
193
|
return;
|
|
193
194
|
}
|
|
@@ -205,7 +206,7 @@ async function schemaCommand(subcommand, rawArgs) {
|
|
|
205
206
|
const env = { ...process.env };
|
|
206
207
|
if (envFile) env.DOTENV_CONFIG_PATH = envFile;
|
|
207
208
|
env[DEV_DATABASE_KIND_ENV] = devDatabaseKind(projectRoot) ?? "";
|
|
208
|
-
|
|
209
|
+
refuseMissingSchemaDir(rawArgs, process.cwd(), backendDir);
|
|
209
210
|
if (subcommand === "introspect") {
|
|
210
211
|
const flags = arg({
|
|
211
212
|
"--database-url": String,
|
|
@@ -231,7 +232,7 @@ async function schemaCommand(subcommand, rawArgs) {
|
|
|
231
232
|
backendDir,
|
|
232
233
|
pluginCli,
|
|
233
234
|
env
|
|
234
|
-
}, [...driverArgs, ...
|
|
235
|
+
}, [...driverArgs, ...schemaDirArgs(projectRoot, driverArgs)]);
|
|
235
236
|
} catch (error) {
|
|
236
237
|
reportSpawnFailure(error);
|
|
237
238
|
process.exit(1);
|
|
@@ -240,22 +241,23 @@ async function schemaCommand(subcommand, rawArgs) {
|
|
|
240
241
|
/** One page per subcommand, so `rebase schema <action> --help` says something. */
|
|
241
242
|
var SCHEMA_ACTION_HELP = {
|
|
242
243
|
generate: {
|
|
243
|
-
usage: "rebase schema generate [--
|
|
244
|
-
summary: "Generate the Drizzle schema from the
|
|
245
|
-
notes: ["--watch regenerates on every change to a
|
|
244
|
+
usage: "rebase schema generate [--schema-dir <dir>] [--output <file>] [--watch]",
|
|
245
|
+
summary: "Generate the Drizzle schema from the tables in backend/schema.",
|
|
246
|
+
notes: ["--watch regenerates on every change to a schema file.", `--schema-dir <dir>: ${SCHEMA_DIR_FLAG_HELP}.`]
|
|
246
247
|
},
|
|
247
248
|
introspect: {
|
|
248
|
-
usage: "rebase schema introspect [--
|
|
249
|
-
summary: "Read an existing database and write
|
|
249
|
+
usage: "rebase schema introspect [--schema-dir <dir>] [--schema <name>] [--force] [--data-inference | --no-data-inference]",
|
|
250
|
+
summary: "Read an existing database and write its tables as defineTable modules into backend/schema.",
|
|
250
251
|
notes: [
|
|
251
|
-
"--force overwrites
|
|
252
|
+
"--force overwrites table modules that are already there.",
|
|
253
|
+
`--schema-dir <dir>: where the tables are written — ${SCHEMA_DIR_FLAG_HELP}.`,
|
|
252
254
|
"--data-inference samples up to 100 rows per table to detect formats, constraints and UI settings; --no-data-inference reads the structure only. Without either it asks, and without a terminal it reads the structure only.",
|
|
253
255
|
"Reads this project's database, the one `rebase db url` prints: --database-url <url> names another; --docker uses the compose one, starting it if needed."
|
|
254
256
|
]
|
|
255
257
|
},
|
|
256
258
|
reconcile: {
|
|
257
259
|
usage: RECONCILE_USAGE,
|
|
258
|
-
summary: "Relax and drop what boot will not: NOT NULL on
|
|
260
|
+
summary: "Relax and drop what boot will not: NOT NULL on columns made nullable, and columns no table declares.",
|
|
259
261
|
notes: [
|
|
260
262
|
"Plans on the running backend (the one `.env` and the cloud link point at), prints the plan, and applies it once you type yes.",
|
|
261
263
|
"A column is dropped only when named: --drop voice_cache.wav. Each drop shows how many rows hold a value.",
|
|
@@ -263,8 +265,8 @@ var SCHEMA_ACTION_HELP = {
|
|
|
263
265
|
]
|
|
264
266
|
},
|
|
265
267
|
stale: {
|
|
266
|
-
usage: "rebase schema stale [--
|
|
267
|
-
summary: "Report generated schema files that no longer match the
|
|
268
|
+
usage: "rebase schema stale [--schema-dir <dir>] [--output <file>] [--fix]",
|
|
269
|
+
summary: "Report generated schema files that no longer match the tables.",
|
|
268
270
|
notes: ["--fix regenerates them instead of only reporting."]
|
|
269
271
|
}
|
|
270
272
|
};
|
|
@@ -293,20 +295,20 @@ ${chalk.green.bold("Usage")}
|
|
|
293
295
|
|
|
294
296
|
${chalk.green.bold("Commands")}
|
|
295
297
|
${chalk.gray("(Commands are provided by your active database driver plugin)")}
|
|
296
|
-
${chalk.blue.bold("generate")} Generate
|
|
297
|
-
${chalk.blue.bold("introspect")} Introspect an existing database
|
|
298
|
-
${chalk.blue.bold("stale")} Report generated schema files that no longer match the
|
|
299
|
-
${chalk.blue.bold("reconcile")} Relax NOT NULL and drop columns the
|
|
298
|
+
${chalk.blue.bold("generate")} Generate the Drizzle schema from the tables in backend/schema
|
|
299
|
+
${chalk.blue.bold("introspect")} Introspect an existing database into defineTable modules in backend/schema
|
|
300
|
+
${chalk.blue.bold("stale")} Report generated schema files that no longer match the tables
|
|
301
|
+
${chalk.blue.bold("reconcile")} Relax NOT NULL and drop columns the tables no longer declare, after review
|
|
300
302
|
|
|
301
|
-
${chalk.green.bold("generate Options")}
|
|
302
|
-
${chalk.blue("--
|
|
303
|
+
${chalk.green.bold("generate / stale Options")}
|
|
304
|
+
${chalk.blue("--schema-dir")} ${SCHEMA_DIR_FLAG_HELP}
|
|
303
305
|
${chalk.blue("--output, -o")} Output path for generated schema
|
|
304
306
|
${chalk.blue("--watch, -w")} Watch for changes and regenerate automatically
|
|
305
307
|
|
|
306
308
|
${chalk.green.bold("introspect Options")}
|
|
307
|
-
${chalk.blue("--
|
|
309
|
+
${chalk.blue("--schema-dir")} Where the tables are written ${chalk.gray("(default: backend/schema)")}
|
|
308
310
|
${chalk.blue("--schema")} Postgres schema to read (default: public)
|
|
309
|
-
${chalk.blue("--force, -f")} Overwrite
|
|
311
|
+
${chalk.blue("--force, -f")} Overwrite table modules that already exist
|
|
310
312
|
${chalk.blue("--database-url")} Read this database instead of the project's own
|
|
311
313
|
${chalk.blue("--docker")} Read the compose database, starting it if needed
|
|
312
314
|
${chalk.blue("--data-inference")} Sample rows to detect formats and constraints ${chalk.gray("(asked when omitted)")}
|
|
@@ -319,4 +321,4 @@ ${chalk.green.bold("stale Options")}
|
|
|
319
321
|
//#endregion
|
|
320
322
|
export { SCHEMA_SUBCOMMANDS, schemaReconcileCommand as i, describeReconcilePlan as n, parseReconcileArgs as r, schemaCommand, RECONCILE_USAGE as t };
|
|
321
323
|
|
|
322
|
-
//# sourceMappingURL=schema-
|
|
324
|
+
//# sourceMappingURL=schema-CdDjv5zI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-CdDjv5zI.js","names":[],"sources":["../src/commands/schema-reconcile.ts","../src/commands/schema.ts"],"sourcesContent":["/**\n * CLI command: rebase schema reconcile\n *\n * The reviewed step for what boot will not do. Boot only ever adds, so a\n * column made nullable keeps its NOT NULL, and a column removed from a table\n * leaves it behind, with its data, and blocking inserts if it was\n * required. This asks the running backend for the plan that fixes both, prints\n * it, and applies it only once confirmed.\n *\n * Through the backend rather than a database URL, because on Rebase Cloud the\n * backend is the one thing that can reach the database — and because it plans\n * against the tables it actually runs, not the ones in this checkout.\n * Columns are dropped only when named with `--drop`; the confirmation sends\n * the plan's digest, so the server runs exactly the statements printed here.\n */\nimport arg from \"arg\";\nimport chalk from \"chalk\";\nimport readline from \"node:readline/promises\";\nimport { RebaseApiError } from \"@rebasepro/client\";\nimport type { SchemaReconcilePlan } from \"@rebasepro/types\";\nimport { requireProjectRoot, readEnvFile } from \"../utils/project\";\nimport { UsageError } from \"../utils/args\";\nimport { cliUserAgent } from \"../utils/version\";\nimport { describeFailure, requireBackendUrl } from \"./api-keys\";\n\nexport const RECONCILE_USAGE = \"rebase schema reconcile [--drop <table>.<column>]... [--yes]\";\n\nexport function parseReconcileArgs(rawArgs: string[]): { drop: string[]; yes: boolean } {\n const flags = arg({ \"--drop\": [String], \"--yes\": Boolean, \"-y\": \"--yes\" }, { argv: rawArgs.slice(2) });\n if (flags._.length > 0) throw new UsageError(`Unexpected argument \"${flags._[0]}\". Usage: ${RECONCILE_USAGE}`);\n return { drop: flags[\"--drop\"] ?? [], yes: flags[\"--yes\"] === true };\n}\n\n/** The plan, as a person reviews it. Returned as lines so it can be tested. */\nexport function describeReconcilePlan(plan: SchemaReconcilePlan): string[] {\n const lines: string[] = [];\n for (const r of plan.relaxed) {\n const why = r.undeclared\n ? `\"${r.collection}\" does not declare it, and every insert fails on it; its data stays`\n : `nullable in \"${r.collection}\", NOT NULL in the database`;\n lines.push(` ${chalk.cyan(\"relax\")} ${r.table}.${r.column} ${chalk.gray(why)}`);\n }\n for (const d of plan.dropped) {\n const rows = d.rowsWithValue === undefined ? \"\" : `${d.rowsWithValue.toLocaleString(\"en-US\")} row(s) hold a value`;\n lines.push(` ${chalk.red(\"drop\")} ${d.table}.${d.column} ${chalk.red(rows)}`);\n }\n const kept = plan.undeclared.filter(u =>\n !plan.dropped.some(d => d.table === u.table && d.column === u.column)\n && !plan.relaxed.some(r => r.undeclared && r.table === u.table && r.column === u.column));\n for (const u of kept) {\n const note = u.blocksInserts\n ? chalk.yellow(\"NOT NULL with no default: every insert fails until it is dropped or relaxed\")\n : chalk.gray(\"no table declares it; kept\");\n lines.push(` ${chalk.gray(\"keep\")} ${u.table}.${u.column} ${note}`);\n }\n return lines;\n}\n\ninterface Backend {\n baseUrl: string;\n post<T>(path: string, body: unknown): Promise<T>;\n}\n\n/** The project's backend, holding the service key. */\nfunction connect(): Backend {\n const projectRoot = requireProjectRoot();\n const env = readEnvFile(projectRoot);\n const serviceKey = env.SERVICE_KEY || env.REBASE_SERVICE_KEY;\n if (!serviceKey) {\n console.error(chalk.red(\"✗ REBASE_SERVICE_KEY not found in .env — required to change the database's schema.\"));\n process.exit(1);\n }\n const baseUrl = requireBackendUrl(env, projectRoot).replace(/\\/+$/, \"\");\n return {\n baseUrl,\n async post<T>(path: string, body: unknown): Promise<T> {\n let response: Response;\n try {\n response = await fetch(`${baseUrl}/api/admin/schema/reconcile${path}`, {\n method: \"POST\",\n headers: {\n \"Authorization\": `Bearer ${serviceKey}`,\n \"Accept\": \"application/json\",\n \"Content-Type\": \"application/json\",\n \"User-Agent\": cliUserAgent()\n },\n body: JSON.stringify(body)\n });\n } catch (error: unknown) {\n throw new RebaseApiError(error instanceof Error ? error.message : String(error), { status: 0, code: \"NETWORK_ERROR\" });\n }\n const answer: unknown = await response.json().catch(() => undefined);\n if (!response.ok) {\n const error = answer && typeof answer === \"object\" && \"error\" in answer && answer.error && typeof answer.error === \"object\"\n ? answer.error as { message?: unknown; code?: unknown; details?: unknown }\n : undefined;\n throw new RebaseApiError(\n typeof error?.message === \"string\" ? error.message : `The server answered ${response.status}.`,\n { status: response.status, code: typeof error?.code === \"string\" ? error.code : undefined, details: error?.details }\n );\n }\n return answer as T;\n }\n };\n}\n\nfunction fail(action: string, error: unknown, baseUrl: string): never {\n for (const line of describeFailure(action, error, baseUrl)) {\n console.error(line.startsWith(\"✗\") ? chalk.red(line) : chalk.gray(line));\n }\n if (error instanceof RebaseApiError && error.status === 404) {\n console.error(chalk.gray(\" This backend has no reconcile route: it needs a runtime that has `rebase schema reconcile`.\"));\n }\n process.exit(1);\n}\n\nexport async function schemaReconcileCommand(rawArgs: string[]): Promise<void> {\n const { drop, yes } = parseReconcileArgs(rawArgs);\n const backend = connect();\n\n let plan: SchemaReconcilePlan;\n try {\n plan = await backend.post<SchemaReconcilePlan>(\"/plan\", { drop });\n } catch (error) {\n fail(\"Failed to plan the reconcile\", error, backend.baseUrl);\n }\n\n console.log(chalk.bold(`\\nSchema reconcile for ${backend.baseUrl}\\n`));\n const described = describeReconcilePlan(plan);\n if (described.length > 0) console.log(described.join(\"\\n\"));\n\n if (plan.problems.length > 0) {\n console.error(chalk.red(\"\\n✗ This plan cannot be applied:\"));\n for (const problem of plan.problems) console.error(chalk.red(` • ${problem}`));\n process.exit(1);\n }\n if (plan.statements.length === 0) {\n console.log(chalk.green(\"✓ Nothing to do: the database already matches what the tables declare.\"));\n }\n if (plan.undeclared.length > plan.dropped.length) {\n console.log(chalk.gray(\" To drop a column no table declares, name it: --drop <table>.<column>\"));\n }\n if (plan.statements.length === 0) return;\n\n console.log(chalk.bold(\"\\nStatements\"));\n for (const statement of plan.statements) console.log(` ${statement}`);\n if (plan.dropped.length > 0) {\n console.log(chalk.red(\"\\n Dropping a column destroys its data. Back the database up first if you may want it back.\"));\n }\n\n if (!yes) {\n if (!process.stdin.isTTY) {\n console.error(chalk.red(\"\\n✗ Not applied: confirming needs a terminal. Re-run with --yes once you have read the plan.\"));\n process.exit(1);\n }\n const rl = readline.createInterface({ input: process.stdin, output: process.stdout });\n const answer = (await rl.question(`\\nApply ${plan.statements.length} statement(s)? Type \"yes\" to continue: `)).trim();\n rl.close();\n if (answer !== \"yes\") {\n console.log(chalk.gray(\"Aborted. Nothing was changed.\"));\n return;\n }\n }\n\n try {\n const result = await backend.post<{ applied: string[] }>(\"/apply\", { drop, confirm: plan.digest });\n console.log(chalk.green(`✓ Applied ${result.applied.length} statement(s).`));\n } catch (error) {\n if (error instanceof RebaseApiError && error.code === \"SCHEMA_RECONCILE_STALE\") {\n console.error(chalk.red(\"✗ Not applied: the database or the tables changed since this plan was made. Run it again to review the new plan.\"));\n process.exit(1);\n }\n fail(\"Failed to apply the reconcile\", error, backend.baseUrl);\n }\n}\n","/**\n * CLI command: rebase schema <action>\n */\nimport arg from \"arg\";\nimport chalk from \"chalk\";\nimport { ensureDockerDatabase, spawnDriverCli } from \"./db\";\nimport {\n requireProjectRoot,\n requireBackendDir,\n getActiveBackendPlugin,\n resolvePluginCliScript,\n resolveTsx,\n findEnvFile,\n exitDependenciesNotInstalled\n} from \"../utils/project\";\nimport { recordEvent } from \"../telemetry\";\nimport { wantsHelp } from \"../utils/args\";\nimport { reportSpawnFailure } from \"../utils/spawn-error\";\nimport { argsFromCommand } from \"../utils/command-words\";\nimport { unknownCommand } from \"../utils/unknown-command\";\nimport { DEV_DATABASE_KIND_ENV, devDatabaseKind, managedNotices, prepareDatabaseEnv } from \"../dev-db/prepare\";\nimport { absolutizeLocalPathArgs } from \"./db\";\nimport { SCHEMA_DIR_FLAG_HELP, refuseMissingSchemaDir, refuseRemovedCollectionsFlag } from \"../utils/path-flags\";\nimport { schemaDirArgs } from \"../utils/schema-dir\";\nimport { RECONCILE_USAGE } from \"./schema-reconcile\";\n\n/**\n * The line handed to the driver, its paths resolved from where the command was\n * run (the driver runs in `backend/`). `--schema` is left alone: on\n * `introspect` it names a Postgres schema, not a file.\n */\nexport function schemaDriverArgs(rawArgs: string[], cwd: string): string[] {\n return absolutizeLocalPathArgs(argsFromCommand(rawArgs, \"schema\"), cwd, [\"--schema-dir\", \"--output\", \"-o\", \"--out\"]);\n}\n\nexport async function schemaCommand(subcommand: string | undefined, rawArgs: string[]): Promise<void> {\n // `--help` is answered here, before `requireProjectRoot` and before the\n // driver is spawned — the same shape `db.ts` already uses, and for the same\n // reason.\n //\n // `cli.ts` rewrites the subcommand to `\"--help\"` only when the user named\n // none, so `rebase schema --help` was covered and `rebase schema generate\n // --help` was not: the flag travelled into `rawArgs.slice(2)` and reached\n // the driver, whose own `schemaCommand` has no `--help` case. It *ran the\n // generator* — overwriting `src/schema.generated.ts` — for a flag whose\n // entire job is to print text. Worse, the first thing it hit outside a\n // project was `requireProjectRoot`, so `rebase schema introspect --help` in\n // an empty directory exited 1 with \"Could not find a Rebase project root\":\n // help you cannot read until you already have a project is help for nobody.\n if (!subcommand || subcommand === \"--help\" || wantsHelp(rawArgs)) {\n printSchemaHelp(subcommand === \"--help\" ? undefined : subcommand);\n return;\n }\n\n // A typo is answered here, in the same words every other family uses.\n //\n // It used to travel to the driver, which said the bare line `Unknown schema\n // command.` — no list, no pointer, no did-you-mean, for a family with three\n // subcommands. The set comes from the help table, so what a typo is measured\n // against and what `--help` prints cannot drift apart.\n if (!SCHEMA_ACTION_HELP[subcommand]) {\n unknownCommand(subcommand, Object.keys(SCHEMA_ACTION_HELP), \"schema\");\n }\n\n // Before anything else runs.\n refuseRemovedCollectionsFlag(rawArgs.slice(2), `schema ${subcommand}`);\n\n const projectRoot = requireProjectRoot();\n\n // Talks to the running backend, not the driver: on Rebase Cloud the\n // backend is the only thing that reaches the database.\n if (subcommand === \"reconcile\") {\n void recordEvent(\"cli.schema\", { subcommand }, { projectRoot });\n const { schemaReconcileCommand } = await import(\"./schema-reconcile\");\n await schemaReconcileCommand(rawArgs);\n return;\n }\n\n // Fire-and-forget, and a no-op unless the developer opted in. Never awaited:\n // the command is what the user is waiting for, and a slow collector must not\n // sit in front of it.\n void recordEvent(\"cli.schema\", { subcommand: subcommand ?? \"none\" }, { projectRoot });\n const backendDir = requireBackendDir(projectRoot);\n\n const activePlugin = getActiveBackendPlugin(backendDir);\n if (!activePlugin) {\n console.error(chalk.red(\"✗ Could not detect an active database plugin.\"));\n console.error(chalk.gray(\" Make sure a package like @rebasepro/server-postgres is installed in backend/package.json.\"));\n process.exit(1);\n }\n\n const pluginCli = resolvePluginCliScript(backendDir, activePlugin);\n if (!pluginCli) {\n exitDependenciesNotInstalled(projectRoot);\n }\n\n // Set up environment with DOTENV_CONFIG_PATH\n const envFile = findEnvFile(projectRoot);\n const env: Record<string, string> = { ...process.env as Record<string, string> };\n if (envFile) {\n env.DOTENV_CONFIG_PATH = envFile;\n }\n // Which database this project is on, so the driver's closing line does not\n // recommend a command that database refuses. A pure decision — nothing is\n // started, which matters here above all: `schema generate` reads the\n // schema directory and writes one file, and booting a database to run it would be a\n // side effect nobody asked for.\n env[DEV_DATABASE_KIND_ENV] = devDatabaseKind(projectRoot) ?? \"\";\n\n refuseMissingSchemaDir(rawArgs, process.cwd(), backendDir);\n\n // `introspect` is the one schema command that reads a database, and it\n // reads the project's — resolved the way every `db` command resolves it,\n // started if that is what it takes. It used to pass `.env` and nothing\n // else, so on the managed database or after `rebase dev --docker` (with\n // the scaffold's DATABASE_URL commented out, on purpose) it said\n // \"DATABASE_URL is not set\", and `--docker` and `--database-url` passed the\n // flag check only to be ignored.\n if (subcommand === \"introspect\") {\n const flags = arg(\n { \"--database-url\": String, \"--docker\": Boolean },\n { argv: rawArgs.slice(2), permissive: true }\n );\n await ensureDockerDatabase(projectRoot, rawArgs);\n const prepared = await prepareDatabaseEnv(projectRoot, {\n flagUrl: flags[\"--database-url\"] ?? null,\n flagDocker: flags[\"--docker\"] === true,\n onProgress: (message) => console.log(chalk.gray(` ${message}`))\n });\n Object.assign(env, prepared.env);\n env[DEV_DATABASE_KIND_ENV] = prepared.database.kind;\n for (const line of managedNotices(prepared)) console.log(chalk.gray(` ${line}`));\n }\n\n try {\n // The one spawn, shared with `db`. This file used to carry its own copy\n // of the tsx-or-node decision; three copies of that rule existed and two\n // were fixed while the third went on spawning plain node.\n const driverArgs = schemaDriverArgs(rawArgs, process.cwd());\n await spawnDriverCli(\n { projectRoot, backendDir, pluginCli, env },\n [...driverArgs, ...schemaDirArgs(projectRoot, driverArgs)]\n );\n } catch (error) {\n // A child that ran and exited non-zero already printed its diagnostics\n // through inherited stdio; a child that never started (ENOENT on tsx,\n // EACCES on the script) printed nothing at all, and this used to exit 1\n // in silence.\n reportSpawnFailure(error);\n process.exit(1);\n }\n}\n\n/** One page per subcommand, so `rebase schema <action> --help` says something. */\nconst SCHEMA_ACTION_HELP: Record<string, { usage: string; summary: string; notes?: string[] }> = {\n generate: {\n usage: \"rebase schema generate [--schema-dir <dir>] [--output <file>] [--watch]\",\n summary: \"Generate the Drizzle schema from the tables in backend/schema.\",\n notes: [\"--watch regenerates on every change to a schema file.\", `--schema-dir <dir>: ${SCHEMA_DIR_FLAG_HELP}.`]\n },\n introspect: {\n usage: \"rebase schema introspect [--schema-dir <dir>] [--schema <name>] [--force] [--data-inference | --no-data-inference]\",\n summary: \"Read an existing database and write its tables as defineTable modules into backend/schema.\",\n notes: [\n \"--force overwrites table modules that are already there.\",\n `--schema-dir <dir>: where the tables are written — ${SCHEMA_DIR_FLAG_HELP}.`,\n \"--data-inference samples up to 100 rows per table to detect formats, constraints and UI settings; \"\n + \"--no-data-inference reads the structure only. Without either it asks, and without a terminal \"\n + \"it reads the structure only.\",\n \"Reads this project's database, the one `rebase db url` prints: --database-url <url> names another; \"\n + \"--docker uses the compose one, starting it if needed.\"\n ]\n },\n reconcile: {\n usage: RECONCILE_USAGE,\n summary: \"Relax and drop what boot will not: NOT NULL on columns made nullable, and columns no table declares.\",\n notes: [\n \"Plans on the running backend (the one `.env` and the cloud link point at), prints the plan, and applies it once you type yes.\",\n \"A column is dropped only when named: --drop voice_cache.wav. Each drop shows how many rows hold a value.\",\n \"--yes skips the prompt, for a plan already read. Needs REBASE_SERVICE_KEY in .env.\"\n ]\n },\n stale: {\n usage: \"rebase schema stale [--schema-dir <dir>] [--output <file>] [--fix]\",\n summary: \"Report generated schema files that no longer match the tables.\",\n notes: [\"--fix regenerates them instead of only reporting.\"]\n }\n};\n\n/** Every subcommand the family dispatches — the help table's keys. */\nexport const SCHEMA_SUBCOMMANDS = Object.keys(SCHEMA_ACTION_HELP);\n\nfunction printSchemaHelp(action?: string) {\n const entry = action ? SCHEMA_ACTION_HELP[action] : undefined;\n if (entry) {\n console.log(`\n${chalk.bold(`rebase schema ${action}`)}\n\n ${entry.summary}\n\n${chalk.green.bold(\"Usage\")}\n ${chalk.blue(entry.usage)}\n${entry.notes?.length ? `\\n${chalk.green.bold(\"Notes\")}\\n${entry.notes.map(n => ` ${chalk.gray(`• ${n}`)}`).join(\"\\n\")}\\n` : \"\"}\n${chalk.gray(\"Run `rebase schema --help` for every subcommand.\")}\n`);\n return;\n }\n\n console.log(`\n${chalk.bold(\"rebase schema\")} — Schema management commands\n\n${chalk.green.bold(\"Usage\")}\n rebase schema ${chalk.blue(\"<command>\")} [options]\n\n${chalk.green.bold(\"Commands\")}\n ${chalk.gray(\"(Commands are provided by your active database driver plugin)\")}\n ${chalk.blue.bold(\"generate\")} Generate the Drizzle schema from the tables in backend/schema\n ${chalk.blue.bold(\"introspect\")} Introspect an existing database into defineTable modules in backend/schema\n ${chalk.blue.bold(\"stale\")} Report generated schema files that no longer match the tables\n ${chalk.blue.bold(\"reconcile\")} Relax NOT NULL and drop columns the tables no longer declare, after review\n\n${chalk.green.bold(\"generate / stale Options\")}\n ${chalk.blue(\"--schema-dir\")} ${SCHEMA_DIR_FLAG_HELP}\n ${chalk.blue(\"--output, -o\")} Output path for generated schema\n ${chalk.blue(\"--watch, -w\")} Watch for changes and regenerate automatically\n\n${chalk.green.bold(\"introspect Options\")}\n ${chalk.blue(\"--schema-dir\")} Where the tables are written ${chalk.gray(\"(default: backend/schema)\")}\n ${chalk.blue(\"--schema\")} Postgres schema to read (default: public)\n ${chalk.blue(\"--force, -f\")} Overwrite table modules that already exist\n ${chalk.blue(\"--database-url\")} Read this database instead of the project's own\n ${chalk.blue(\"--docker\")} Read the compose database, starting it if needed\n ${chalk.blue(\"--data-inference\")} Sample rows to detect formats and constraints ${chalk.gray(\"(asked when omitted)\")}\n ${chalk.blue(\"--no-data-inference\")} Read the structure only, without asking\n\n${chalk.green.bold(\"stale Options\")}\n ${chalk.blue(\"--fix\")} Regenerate the stale files instead of only reporting them\n`);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,IAAa,kBAAkB;AAE/B,SAAgB,mBAAmB,SAAqD;CACpF,MAAM,QAAQ,IAAI;EAAE,UAAU,CAAC,MAAM;EAAG,SAAS;EAAS,MAAM;CAAQ,GAAG,EAAE,MAAM,QAAQ,MAAM,CAAC,EAAE,CAAC;CACrG,IAAI,MAAM,EAAE,SAAS,GAAG,MAAM,IAAI,WAAW,wBAAwB,MAAM,EAAE,GAAG,YAAY,iBAAiB;CAC7G,OAAO;EAAE,MAAM,MAAM,aAAa,CAAC;EAAG,KAAK,MAAM,aAAa;CAAK;AACvE;;AAGA,SAAgB,sBAAsB,MAAqC;CACvE,MAAM,QAAkB,CAAC;CACzB,KAAK,MAAM,KAAK,KAAK,SAAS;EAC1B,MAAM,MAAM,EAAE,aACR,IAAI,EAAE,WAAW,uEACjB,gBAAgB,EAAE,WAAW;EACnC,MAAM,KAAK,KAAK,MAAM,KAAK,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,EAAE,OAAO,IAAI,MAAM,KAAK,GAAG,GAAG;CACrF;CACA,KAAK,MAAM,KAAK,KAAK,SAAS;EAC1B,MAAM,OAAO,EAAE,kBAAkB,KAAA,IAAY,KAAK,GAAG,EAAE,cAAc,eAAe,OAAO,EAAE;EAC7F,MAAM,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AO,EAAE;CACvB;AACD"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
|
|
2
|
+
import { C as resolveBackendPaths, _ as findBackendApp, a as DEFAULT_TABLES_DIR, b as loadManifest } from "./manifest-C3uLDrrJ.js";
|
|
3
|
+
import path from "path";
|
|
4
|
+
//#region src/utils/schema-dir.ts
|
|
5
|
+
/**
|
|
6
|
+
* Where this project's tables are declared: one answer for every command.
|
|
7
|
+
*
|
|
8
|
+
* `rebase.json`'s `apps.<backend>.tables` names the directory whose `index.ts`
|
|
9
|
+
* exports the tables (default `backend/schema`). Every command that reads the
|
|
10
|
+
* schema — the dev runtime and watcher, `rebase build`, `verify`, `doctor`,
|
|
11
|
+
* `generate-sdk`, `generate view`, `console`, and the driver's `db` / `schema`
|
|
12
|
+
* commands — asks here, so a project that moves the directory moves it for all
|
|
13
|
+
* of them. The previous layout had one resolver too, and still grew five
|
|
14
|
+
* commands that hardcoded `config/collections` beside it; this module is the
|
|
15
|
+
* only place the default is spelled.
|
|
16
|
+
*
|
|
17
|
+
* A directory typed on the command line still wins wherever a command takes
|
|
18
|
+
* one; this is only the default.
|
|
19
|
+
*/
|
|
20
|
+
var schema_dir_exports = /* @__PURE__ */ __exportAll({
|
|
21
|
+
SCHEMA_DIR_FLAG: () => SCHEMA_DIR_FLAG,
|
|
22
|
+
resolveSchemaDir: () => resolveSchemaDir,
|
|
23
|
+
resolveTablesDir: () => resolveTablesDir,
|
|
24
|
+
schemaDirArgs: () => schemaDirArgs,
|
|
25
|
+
schemaDirFlag: () => schemaDirFlag
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* The flag that hands the driver CLI (`@rebasepro/server-postgres`) the schema
|
|
29
|
+
* directory, as an absolute path.
|
|
30
|
+
*
|
|
31
|
+
* The receiving end is the driver's own argument spec: when the driver slice
|
|
32
|
+
* renames its flag, this constant and {@link schemaDirFlag} are the only CLI
|
|
33
|
+
* lines that change.
|
|
34
|
+
*/
|
|
35
|
+
var SCHEMA_DIR_FLAG = "--schema-dir";
|
|
36
|
+
/** The tables directory, relative to the project root, as the backend app declares it. */
|
|
37
|
+
function resolveTablesDir(projectRoot) {
|
|
38
|
+
try {
|
|
39
|
+
const backend = findBackendApp(loadManifest(projectRoot).manifest);
|
|
40
|
+
if (backend) return resolveBackendPaths(backend.app, projectRoot).tables;
|
|
41
|
+
} catch {}
|
|
42
|
+
return DEFAULT_TABLES_DIR;
|
|
43
|
+
}
|
|
44
|
+
/** The tables directory, absolute. */
|
|
45
|
+
function resolveSchemaDir(projectRoot) {
|
|
46
|
+
return path.join(projectRoot, resolveTablesDir(projectRoot));
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The driver argv naming `dir` as the schema directory: `["--schema-dir", dir]`.
|
|
50
|
+
*
|
|
51
|
+
* The whole CLI → driver contract for this flag, in one function. `dir` is
|
|
52
|
+
* absolute — the driver runs with `cwd: backend/`, so a relative path would be
|
|
53
|
+
* resolved from a directory the user never typed it in.
|
|
54
|
+
*/
|
|
55
|
+
function schemaDirFlag(dir) {
|
|
56
|
+
return [SCHEMA_DIR_FLAG, dir];
|
|
57
|
+
}
|
|
58
|
+
/** Whether a command line already names a schema directory. */
|
|
59
|
+
function namesSchemaDir(args) {
|
|
60
|
+
return args.some((arg) => arg === "--schema-dir" || arg.startsWith(`--schema-dir=`));
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The driver commands that read the schema directory. Keyed as the driver's
|
|
64
|
+
* argv starts: domain, then subcommand (or the bare command for the
|
|
65
|
+
* single-word ones).
|
|
66
|
+
*/
|
|
67
|
+
var DRIVER_COMMANDS_READING_SCHEMA = /* @__PURE__ */ new Set([
|
|
68
|
+
"db push",
|
|
69
|
+
"db generate",
|
|
70
|
+
"db migrate",
|
|
71
|
+
"schema generate",
|
|
72
|
+
"schema introspect",
|
|
73
|
+
"schema stale",
|
|
74
|
+
"doctor",
|
|
75
|
+
"console"
|
|
76
|
+
]);
|
|
77
|
+
/**
|
|
78
|
+
* {@link schemaDirFlag} for a driver command line, or nothing.
|
|
79
|
+
*
|
|
80
|
+
* `driverArgs` is the line as the driver gets it (`["db", "push", …]`,
|
|
81
|
+
* `["doctor", …]`). Nothing for a command that does not read the schema,
|
|
82
|
+
* nothing when the line already names a directory, and nothing when the
|
|
83
|
+
* project keeps its tables at the default — the driver's own default is
|
|
84
|
+
* `backend/schema` (`schema` from its `cwd`), so a conventional project's
|
|
85
|
+
* command lines stay as short as they were.
|
|
86
|
+
*/
|
|
87
|
+
function schemaDirArgs(projectRoot, driverArgs) {
|
|
88
|
+
const command = DRIVER_COMMANDS_READING_SCHEMA.has(driverArgs[0]) ? driverArgs[0] : `${driverArgs[0]} ${driverArgs[1]}`;
|
|
89
|
+
if (!DRIVER_COMMANDS_READING_SCHEMA.has(command)) return [];
|
|
90
|
+
if (namesSchemaDir(driverArgs)) return [];
|
|
91
|
+
const dir = resolveSchemaDir(projectRoot);
|
|
92
|
+
if (dir === path.join(projectRoot, "backend/schema")) return [];
|
|
93
|
+
return schemaDirFlag(dir);
|
|
94
|
+
}
|
|
95
|
+
//#endregion
|
|
96
|
+
export { schema_dir_exports as i, resolveSchemaDir as n, schemaDirArgs as r, SCHEMA_DIR_FLAG as t };
|
|
97
|
+
|
|
98
|
+
//# sourceMappingURL=schema-dir-Cd1kvYbf.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-dir-Cd1kvYbf.js","names":[],"sources":["../src/utils/schema-dir.ts"],"sourcesContent":["/**\n * Where this project's tables are declared: one answer for every command.\n *\n * `rebase.json`'s `apps.<backend>.tables` names the directory whose `index.ts`\n * exports the tables (default `backend/schema`). Every command that reads the\n * schema — the dev runtime and watcher, `rebase build`, `verify`, `doctor`,\n * `generate-sdk`, `generate view`, `console`, and the driver's `db` / `schema`\n * commands — asks here, so a project that moves the directory moves it for all\n * of them. The previous layout had one resolver too, and still grew five\n * commands that hardcoded `config/collections` beside it; this module is the\n * only place the default is spelled.\n *\n * A directory typed on the command line still wins wherever a command takes\n * one; this is only the default.\n */\nimport path from \"path\";\nimport { DEFAULT_TABLES_DIR, findBackendApp, loadManifest, resolveBackendPaths } from \"../manifest\";\n\n/**\n * The flag that hands the driver CLI (`@rebasepro/server-postgres`) the schema\n * directory, as an absolute path.\n *\n * The receiving end is the driver's own argument spec: when the driver slice\n * renames its flag, this constant and {@link schemaDirFlag} are the only CLI\n * lines that change.\n */\nexport const SCHEMA_DIR_FLAG = \"--schema-dir\";\n\n/** The tables directory, relative to the project root, as the backend app declares it. */\nexport function resolveTablesDir(projectRoot: string): string {\n try {\n const backend = findBackendApp(loadManifest(projectRoot).manifest);\n if (backend) return resolveBackendPaths(backend.app, projectRoot).tables;\n } catch {\n // A malformed rebase.json is reported by the commands that own it; the\n // conventional layout is the answer until then.\n }\n return DEFAULT_TABLES_DIR;\n}\n\n/** The tables directory, absolute. */\nexport function resolveSchemaDir(projectRoot: string): string {\n return path.join(projectRoot, resolveTablesDir(projectRoot));\n}\n\n/**\n * The driver argv naming `dir` as the schema directory: `[\"--schema-dir\", dir]`.\n *\n * The whole CLI → driver contract for this flag, in one function. `dir` is\n * absolute — the driver runs with `cwd: backend/`, so a relative path would be\n * resolved from a directory the user never typed it in.\n */\nexport function schemaDirFlag(dir: string): string[] {\n return [SCHEMA_DIR_FLAG, dir];\n}\n\n/** Whether a command line already names a schema directory. */\nfunction namesSchemaDir(args: readonly string[]): boolean {\n return args.some(arg => arg === SCHEMA_DIR_FLAG || arg.startsWith(`${SCHEMA_DIR_FLAG}=`));\n}\n\n/**\n * The driver commands that read the schema directory. Keyed as the driver's\n * argv starts: domain, then subcommand (or the bare command for the\n * single-word ones).\n */\nconst DRIVER_COMMANDS_READING_SCHEMA = new Set([\n \"db push\",\n \"db generate\",\n // It stamps the policies the migration created as the tables' rules make them.\n \"db migrate\",\n \"schema generate\",\n // It writes the introspected tables there.\n \"schema introspect\",\n \"schema stale\",\n \"doctor\",\n \"console\"\n]);\n\n/**\n * {@link schemaDirFlag} for a driver command line, or nothing.\n *\n * `driverArgs` is the line as the driver gets it (`[\"db\", \"push\", …]`,\n * `[\"doctor\", …]`). Nothing for a command that does not read the schema,\n * nothing when the line already names a directory, and nothing when the\n * project keeps its tables at the default — the driver's own default is\n * `backend/schema` (`schema` from its `cwd`), so a conventional project's\n * command lines stay as short as they were.\n */\nexport function schemaDirArgs(projectRoot: string, driverArgs: readonly string[]): string[] {\n const command = DRIVER_COMMANDS_READING_SCHEMA.has(driverArgs[0])\n ? driverArgs[0]\n : `${driverArgs[0]} ${driverArgs[1]}`;\n if (!DRIVER_COMMANDS_READING_SCHEMA.has(command)) return [];\n if (namesSchemaDir(driverArgs)) return [];\n const dir = resolveSchemaDir(projectRoot);\n if (dir === path.join(projectRoot, DEFAULT_TABLES_DIR)) return [];\n return schemaDirFlag(dir);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,IAAa,kBAAkB;;AAG/B,SAAgB,iBAAiB,aAA6B;CAC1D,IAAI;EACA,MAAM,UAAU,eAAe,aAAa,WAAW,CAAC,CAAC,QAAQ;EACjE,IAAI,SAAS,OAAO,oBAAoB,QAAQ,KAAK,WAAW,CAAC,CAAC;CACtE,QAAQ,CAGR;CACA,OAAO;AACX;;AAGA,SAAgB,iBAAiB,aAA6B;CAC1D,OAAO,KAAK,KAAK,aAAa,iBAAiB,WAAW,CAAC;AAC/D;;;;;;;;AASA,SAAgB,cAAc,KAAuB;CACjD,OAAO,CAAC,iBAAiB,GAAG;AAChC;;AAGA,SAAS,eAAe,MAAkC;CACtD,OAAO,KAAK,MAAK,QAAO,QAAA,kBAA2B,IAAI,WAAW,eAAqB,CAAC;AAC5F;;;;;;AAOA,IAAM,iDAAiC,IAAI,IAAI;CAC3C;CACA;CAEA;CACA;CAEA;CACA;CACA;CACA;AACJ,CAAC;;;;;;;;;;;AAYD,SAAgB,cAAc,aAAqB,YAAyC;CACxF,MAAM,UAAU,+BAA+B,IAAI,WAAW,EAAE,IAC1D,WAAW,KACX,GAAG,WAAW,GAAG,GAAG,WAAW;CACrC,IAAI,CAAC,+BAA+B,IAAI,OAAO,GAAG,OAAO,CAAC;CAC1D,IAAI,eAAe,UAAU,GAAG,OAAO,CAAC;CACxC,MAAM,MAAM,iBAAiB,WAAW;CACxC,IAAI,QAAQ,KAAK,KAAK,aAAA,gBAA+B,GAAG,OAAO,CAAC;CAChE,OAAO,cAAc,GAAG;AAC5B"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
//#region src/utils/schema-text.ts
|
|
4
|
+
/**
|
|
5
|
+
* The tables a schema directory declares, read as text — never imported.
|
|
6
|
+
*
|
|
7
|
+
* For the commands that must not run a project's code to answer a question
|
|
8
|
+
* about its files: `rebase doctor` (two tables claiming one slug) and `rebase
|
|
9
|
+
* generate view --collection` (does that table exist, before writing a view
|
|
10
|
+
* for it). A schema file may import anything the project depends on; reading
|
|
11
|
+
* it is enough to see each `defineTable("name", …)`.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Every module under the schema directory, depth first and sorted: what the
|
|
15
|
+
* loader would import. Tests, declaration files, dotfiles and `node_modules`
|
|
16
|
+
* are not modules of the schema.
|
|
17
|
+
*/
|
|
18
|
+
function schemaModules(dir) {
|
|
19
|
+
const out = [];
|
|
20
|
+
const walk = (current) => {
|
|
21
|
+
let entries;
|
|
22
|
+
try {
|
|
23
|
+
entries = fs.readdirSync(current, { withFileTypes: true });
|
|
24
|
+
} catch {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {
|
|
28
|
+
if (entry.name.startsWith(".") || entry.name === "node_modules") continue;
|
|
29
|
+
const full = path.join(current, entry.name);
|
|
30
|
+
if (entry.isDirectory()) walk(full);
|
|
31
|
+
else if (/\.(ts|js|mts|mjs)$/.test(entry.name) && !/\.(d|test|spec)\./.test(entry.name)) out.push(full);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
walk(dir);
|
|
35
|
+
return out;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The slug of every table one schema file's source declares.
|
|
39
|
+
*
|
|
40
|
+
* Each `defineTable("name", …)` / `defineAuthTable` / `defineView` call is a
|
|
41
|
+
* table whose slug is its name, unless a `slug: "…"` appears before the next
|
|
42
|
+
* definition. A computed name or slug is simply not seen, which is the right
|
|
43
|
+
* failure for checks that only ever report or refuse.
|
|
44
|
+
*/
|
|
45
|
+
function declaredTableSlugs(source) {
|
|
46
|
+
const calls = [...source.matchAll(/\bdefine(?:Auth)?(?:Table|View)\s*(?:<[^>]*>)?\(\s*["'`]([^"'`]+)["'`]/g)];
|
|
47
|
+
return calls.map((call, i) => {
|
|
48
|
+
const end = i + 1 < calls.length ? calls[i + 1].index : source.length;
|
|
49
|
+
const body = source.slice(call.index + call[0].length, end);
|
|
50
|
+
return /\bslug:\s*["'`]([^"'`]+)["'`]/.exec(body)?.[1] ?? call[1];
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/** Every table the schema directory's files declare, in file order. */
|
|
54
|
+
function declaredTables(schemaDir) {
|
|
55
|
+
const tables = [];
|
|
56
|
+
for (const file of schemaModules(schemaDir)) {
|
|
57
|
+
let source;
|
|
58
|
+
try {
|
|
59
|
+
source = fs.readFileSync(file, "utf-8");
|
|
60
|
+
} catch {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
for (const slug of declaredTableSlugs(source)) tables.push({
|
|
64
|
+
slug,
|
|
65
|
+
file
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
return tables;
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
export { declaredTables as t };
|
|
72
|
+
|
|
73
|
+
//# sourceMappingURL=schema-text-CpNrsuMe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-text-CpNrsuMe.js","names":[],"sources":["../src/utils/schema-text.ts"],"sourcesContent":["/**\n * The tables a schema directory declares, read as text — never imported.\n *\n * For the commands that must not run a project's code to answer a question\n * about its files: `rebase doctor` (two tables claiming one slug) and `rebase\n * generate view --collection` (does that table exist, before writing a view\n * for it). A schema file may import anything the project depends on; reading\n * it is enough to see each `defineTable(\"name\", …)`.\n */\nimport fs from \"fs\";\nimport path from \"path\";\n\n/** A table one schema file declares. */\nexport interface DeclaredTable {\n /** The API slug: the definition's name, or its `slug: \"…\"` override. */\n slug: string;\n /** The file it is declared in, absolute. */\n file: string;\n}\n\n/**\n * Every module under the schema directory, depth first and sorted: what the\n * loader would import. Tests, declaration files, dotfiles and `node_modules`\n * are not modules of the schema.\n */\nexport function schemaModules(dir: string): string[] {\n const out: string[] = [];\n const walk = (current: string): void => {\n let entries: fs.Dirent[];\n try {\n entries = fs.readdirSync(current, { withFileTypes: true });\n } catch {\n return;\n }\n for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {\n if (entry.name.startsWith(\".\") || entry.name === \"node_modules\") continue;\n const full = path.join(current, entry.name);\n if (entry.isDirectory()) walk(full);\n else if (/\\.(ts|js|mts|mjs)$/.test(entry.name) && !/\\.(d|test|spec)\\./.test(entry.name)) out.push(full);\n }\n };\n walk(dir);\n return out;\n}\n\n/**\n * The slug of every table one schema file's source declares.\n *\n * Each `defineTable(\"name\", …)` / `defineAuthTable` / `defineView` call is a\n * table whose slug is its name, unless a `slug: \"…\"` appears before the next\n * definition. A computed name or slug is simply not seen, which is the right\n * failure for checks that only ever report or refuse.\n */\nexport function declaredTableSlugs(source: string): string[] {\n const calls = [...source.matchAll(/\\bdefine(?:Auth)?(?:Table|View)\\s*(?:<[^>]*>)?\\(\\s*[\"'`]([^\"'`]+)[\"'`]/g)];\n return calls.map((call, i) => {\n const end = i + 1 < calls.length ? calls[i + 1].index : source.length;\n const body = source.slice(call.index + call[0].length, end);\n return /\\bslug:\\s*[\"'`]([^\"'`]+)[\"'`]/.exec(body)?.[1] ?? call[1];\n });\n}\n\n/** Every table the schema directory's files declare, in file order. */\nexport function declaredTables(schemaDir: string): DeclaredTable[] {\n const tables: DeclaredTable[] = [];\n for (const file of schemaModules(schemaDir)) {\n let source: string;\n try {\n source = fs.readFileSync(file, \"utf-8\");\n } catch {\n continue;\n }\n for (const slug of declaredTableSlugs(source)) tables.push({ slug, file });\n }\n return tables;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAyBA,SAAgB,cAAc,KAAuB;CACjD,MAAM,MAAgB,CAAC;CACvB,MAAM,QAAQ,YAA0B;EACpC,IAAI;EACJ,IAAI;GACA,UAAU,GAAG,YAAY,SAAS,EAAE,eAAe,KAAK,CAAC;EAC7D,QAAQ;GACJ;EACJ;EACA,KAAK,MAAM,SAAS,QAAQ,MAAM,GAAG,MAAM,EAAE,KAAK,cAAc,EAAE,IAAI,CAAC,GAAG;GACtE,IAAI,MAAM,KAAK,WAAW,GAAG,KAAK,MAAM,SAAS,gBAAgB;GACjE,MAAM,OAAO,KAAK,KAAK,SAAS,MAAM,IAAI;GAC1C,IAAI,MAAM,YAAY,GAAG,KAAK,IAAI;QAC7B,IAAI,qBAAqB,KAAK,MAAM,IAAI,KAAK,CAAC,oBAAoB,KAAK,MAAM,IAAI,GAAG,IAAI,KAAK,IAAI;EAC1G;CACJ;CACA,KAAK,GAAG;CACR,OAAO;AACX;;;;;;;;;AAUA,SAAgB,mBAAmB,QAA0B;CACzD,MAAM,QAAQ,CAAC,GAAG,OAAO,SAAS,yEAAyE,CAAC;CAC5G,OAAO,MAAM,KAAK,MAAM,MAAM;EAC1B,MAAM,MAAM,IAAI,IAAI,MAAM,SAAS,MAAM,IAAI,EAAE,CAAC,QAAQ,OAAO;EAC/D,MAAM,OAAO,OAAO,MAAM,KAAK,QAAQ,KAAK,EAAE,CAAC,QAAQ,GAAG;EAC1D,OAAO,gCAAgC,KAAK,IAAI,CAAC,GAAG,MAA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