@rebasepro/cli 0.30.1 → 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-DtADfWwn.js → cloud-CYMk92iG.js} +72 -71
- 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/context.d.ts +1 -1
- package/dist/commands/cloud/init.d.ts +2 -2
- 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-DtADfWwn.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,6 @@
|
|
|
1
1
|
# Rebase AI Coding Rules
|
|
2
2
|
|
|
3
|
-
This is a **headless** Rebase project: a REST API, auth, storage and realtime over your PostgreSQL database, with no admin panel. There
|
|
3
|
+
This is a **headless** Rebase project: a REST API, auth, storage and realtime over your PostgreSQL database, with no admin panel. There is no `backend/schema/` and no generated schema — the server reads the database schema at boot and serves each table that has row-level security enabled. `README.md` shows the SQL.
|
|
4
4
|
|
|
5
5
|
`.mcp.json` in this directory wires the Rebase MCP server up already — no login, no token: it reads `.rebase/state.json` while `pnpm dev` is running. For the full skills (auth, RLS, functions, storage, deployment), run `pnpm skills:install`, or `rebase skills install --agent <claude|cursor|windsurf|gemini|codex|kiro|copilot>` to pick one.
|
|
6
6
|
|
|
@@ -10,29 +10,29 @@ This is a **headless** Rebase project: a REST API, auth, storage and realtime ov
|
|
|
10
10
|
|---|---|
|
|
11
11
|
| `pnpm dev` | The backend and the managed development database, together |
|
|
12
12
|
| `rebase db url` | Print the connection string in use — it pipes straight into `psql` |
|
|
13
|
-
| `pnpm db:migrate` | Apply the migration files in `backend/drizzle/migrations`, on the managed development database or your own PostgreSQL. A headless project
|
|
14
|
-
| `pnpm schema:introspect` | Existing tables →
|
|
15
|
-
| `pnpm generate:sdk` | Regenerate the typed client from `
|
|
13
|
+
| `pnpm db:migrate` | Apply the migration files in `backend/drizzle/migrations`, on the managed development database or your own PostgreSQL. A headless project declares no tables, so nothing writes those files for it — `rebase db generate` has no schema to generate from — and until you add one there is nothing to apply. A file you write by hand needs `pnpm exec atlas migrate hash --dir file://drizzle/migrations`, run in `backend/`, before it applies |
|
|
14
|
+
| `pnpm schema:introspect` | Existing tables → `defineTable(...)` files in `backend/schema/`. That directory makes the code the schema; see rule 1 |
|
|
15
|
+
| `pnpm generate:sdk` | Regenerate the typed client from `backend/schema/` — so in a headless project it has nothing to read until you introspect. Once there are tables there, `pnpm dev` does this on start and on every save; the script is for CI and for when `pnpm dev` is not running |
|
|
16
16
|
| `pnpm build` then `pnpm start` | Build the deployable bundle, then run it |
|
|
17
17
|
| `pnpm skills:install` | Install the Rebase skills for your assistant |
|
|
18
18
|
| `pnpm example` | Run `scripts/example.ts` against the running backend: a health check, and an SDK call to uncomment |
|
|
19
19
|
| `rebase doctor` | Checks the environment and the database connection — run this before guessing |
|
|
20
|
-
| `rebase resources --write` | After declaring a database, bucket or topic in `
|
|
20
|
+
| `rebase resources --write` | After declaring a database, bucket or topic in `backend/resources.ts`: regenerate `rebase.resources.json` and commit it (`pnpm build` does this too) |
|
|
21
21
|
| `pnpm deploy` | Deploys this project. Never run it; see below |
|
|
22
22
|
|
|
23
23
|
## Never
|
|
24
24
|
|
|
25
25
|
- **Never deploy.** `pnpm deploy`, `rebase cloud deploy`, `firebase deploy`, `gcloud run deploy` — print the command and let the human run it, even when the task list ends in "deploy" and the tests are green.
|
|
26
26
|
- **Never edit `.env`.** It holds generated secrets and the connection string. Add a variable by asking, and document it in `.env.example`.
|
|
27
|
-
- **Never edit `rebase.resources.json`.** It is generated from `
|
|
27
|
+
- **Never edit `rebase.resources.json`.** It is generated from `backend/resources.ts` — declare there, then `rebase resources --write`.
|
|
28
28
|
- **Never pass `--allow-destructive`** to anything pointed at a database that is not the local development one. It drops columns and tables.
|
|
29
29
|
- **Never read or write application rows as the database owner from code.** The schema is SQL here; owner-level data access (`rebase.sql()`, a Drizzle client) is not, because it skips row-level security, validation and hooks. Analytics have an SDK form — `aggregate()` with `countDistinct`, `mode`, `percentile`, `distinct`, groups by `lower(…)`, `day(…)` or `unnest(tags)`, and `fingerprint()` to know whether a table changed — and bulk writes are `createMany` / `updateMany`, one statement per batch. When those do not fit, `getSql(c)` in a function runs one statement as the caller, under the same policies as the API: read-only unless `{ write: true }`, the query text yours and every value in `params`.
|
|
30
30
|
|
|
31
31
|
## Core rules
|
|
32
32
|
|
|
33
|
-
1. **The database is the schema.** Change it with SQL — `rebase db url` gives `psql` the connection string — or with migration files, then restart `pnpm dev`: the server reads the tables at boot. Do not create `
|
|
33
|
+
1. **The database is the schema.** Change it with SQL — `rebase db url` gives `psql` the connection string — or with migration files, then restart `pnpm dev`: the server reads the tables at boot. Do not create `backend/schema/` to describe a table; a project with `backend/schema/index.ts` serves the tables declared there instead of reading the database, which is a different project (`README.md`, "Declaring your tables in code").
|
|
34
34
|
2. **A table is served only with row-level security enabled.** Until then the server skips it and logs why — deliberately, so a table is never exposed just by existing — and with RLS on but no policy it is served and returns no rows. The policy *is* the authorization model: write the rule that says whose row it is, using the `rebase` schema's SQL functions `uid()`, `roles()` and `jwt()`, never a policy that admits everyone just to make rows appear.
|
|
35
|
-
3. **Storage is not under row-level security.** `
|
|
35
|
+
3. **Storage is not under row-level security.** `backend/storage.ts` exports `storageAuthorize`, the whole access model for files, and a production deployment with file storage enabled refuses to boot without one. Change the rule there to match your application; do not delete it.
|
|
36
36
|
4. **Use the SDK**: server-side that is `rebase.dataAsAdmin.<table>` for work done as the service identity, or `getDriver(c)` inside a function when the read should run as the caller. The server client has no plain `data` accessor — it is omitted precisely so that the choice of identity is written down.
|
|
37
37
|
5. **Guard every custom route**: routes in `backend/functions/` are mounted **without** an auth requirement — webhook receivers need that — so each one is public until you guard it. Import `requireAuth` / `requireAdmin` from `@rebasepro/server/functions` and pass them in the route's own middleware slot (`app.post("/", requireAuth, handler)`), not via `app.use()`, which only covers routes declared below it. Reading `getUser(c)` is not a guard: an anonymous caller gets `undefined` and the handler still runs. See `backend/functions/hello.ts` for all three tiers.
|
|
38
38
|
6. **In `backend/functions/`, always import from `@rebasepro/server/functions`** — never from `@rebasepro/server`. Both work today; the subpath is the portable one, and it also gives you the typed context accessors (`getUser`, `getDriver`, `requireDriver`) instead of casting `c.get("user")`. The package root is for a server entrypoint, not for route handlers.
|
|
@@ -11,9 +11,8 @@ import type { StorageAuthorize } from "@rebasepro/types";
|
|
|
11
11
|
* they can `GET /storage/list?prefix=` to enumerate every key, then read, overwrite
|
|
12
12
|
* or delete any of them.
|
|
13
13
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* declare and nowhere else to put this.
|
|
14
|
+
* The runtime reads it from `backend/storage.ts`, whether or not this project
|
|
15
|
+
* declares its tables in `backend/schema/`.
|
|
17
16
|
*
|
|
18
17
|
* ## The default this starter ships
|
|
19
18
|
*
|
|
@@ -41,7 +40,7 @@ import type { StorageAuthorize } from "@rebasepro/types";
|
|
|
41
40
|
* export const storageAuthorize: StorageAuthorize = async ({ key, user, operation, data }) => {
|
|
42
41
|
* if (operation === "read" && key.startsWith("public/")) return true;
|
|
43
42
|
* if (!user) return false;
|
|
44
|
-
* const row = (await data?.
|
|
43
|
+
* const row = (await data?.table("attachments").find({
|
|
45
44
|
* where: { storage_key: ["==", key] }, limit: 1
|
|
46
45
|
* }))?.data?.[0];
|
|
47
46
|
* return row?.owner_id === user.uid;
|
|
@@ -13,18 +13,16 @@
|
|
|
13
13
|
"resolveJsonModule": true,
|
|
14
14
|
"declaration": true,
|
|
15
15
|
"sourceMap": true,
|
|
16
|
-
"rootDir": "
|
|
16
|
+
"rootDir": "."
|
|
17
17
|
},
|
|
18
|
-
// `functions/` as well as `src/`, because this
|
|
19
|
-
//
|
|
20
|
-
// entrypoint lives behind `rebase eject`. An include matching only
|
|
21
|
-
// directory is TS18003 — tsc reports "no inputs" as an error
|
|
18
|
+
// `functions/` as well as `src/`, because this project has nothing in src:
|
|
19
|
+
// its tables come from the database, so there is no generated schema, and
|
|
20
|
+
// the server entrypoint lives behind `rebase eject`. An include matching only
|
|
21
|
+
// an empty directory is TS18003 — tsc reports "no inputs" as an error.
|
|
22
22
|
//
|
|
23
|
-
// `rootDir` is
|
|
24
|
-
//
|
|
25
|
-
//
|
|
26
|
-
// lands at `dist/backend/src/…`, which is what `scripts.start` runs. Inferring
|
|
27
|
-
// it stopped being an option in TypeScript 6 (TS5011).
|
|
23
|
+
// `rootDir` is `.`: everything compiled lives under backend/, so the emit
|
|
24
|
+
// mirrors it (`dist/functions/…`, `dist/src/…`). Inferring it stopped being
|
|
25
|
+
// an option in TypeScript 6 (TS5011).
|
|
28
26
|
//
|
|
29
27
|
// `crons/` too: `rebase build` compiles it through a generated tsconfig, but
|
|
30
28
|
// an ejected project builds with *this* file, so leaving it out meant an
|
|
@@ -33,6 +31,6 @@
|
|
|
33
31
|
//
|
|
34
32
|
// `scripts/` because that is where the Scripts page puts a script that opens
|
|
35
33
|
// the project with `openRebase`, and a type error there should be one `tsc`
|
|
36
|
-
// reports.
|
|
37
|
-
"include": ["src/**/*", "functions/**/*", "crons/**/*", "scripts/**/*"]
|
|
34
|
+
// reports. `schema/` for the day you declare tables in code (see the README).
|
|
35
|
+
"include": ["src/**/*", "schema/**/*", "functions/**/*", "crons/**/*", "scripts/**/*", "generated/**/*", "resources.ts", "storage.ts", "hooks.ts"]
|
|
38
36
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every table this backend serves. A `defineTable` that is not exported from
|
|
3
|
+
* here is refused at boot and by `rebase db generate`.
|
|
4
|
+
*
|
|
5
|
+
* Add a table as `backend/schema/<name>.ts`:
|
|
6
|
+
*
|
|
7
|
+
* import { defineTable, col } from "@rebasepro/server/schema";
|
|
8
|
+
*
|
|
9
|
+
* export const notes = defineTable("notes", {
|
|
10
|
+
* columns: {
|
|
11
|
+
* id: col.uuid().primaryKey().defaultRandom(),
|
|
12
|
+
* body: col.text().notNull()
|
|
13
|
+
* },
|
|
14
|
+
* rls: "admin-only"
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* then export it here. `pnpm dev` creates it.
|
|
18
|
+
*/
|
|
19
|
+
export { users } from "./users";
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import "@fontsource/jetbrains-mono";
|
|
2
|
+
import "@fontsource-variable/inter";
|
|
3
|
+
import "@fontsource-variable/instrument-sans";
|
|
4
|
+
|
|
5
|
+
import { Rebase, RebaseAuth, useRebaseAuthController } from "@rebasepro/app";
|
|
6
|
+
import { RebaseCMS, RebaseShell } from "@rebasepro/cms";
|
|
7
|
+
import { ErrorBoundary } from "@rebasepro/ui";
|
|
8
|
+
import { RebaseStudio } from "@rebasepro/studio";
|
|
9
|
+
import { createRebaseClient } from "@rebasepro/client";
|
|
10
|
+
import { usersCms } from "./cms/users";
|
|
11
|
+
// How the collection editor laid out the tables in development (labels, columns, views).
|
|
12
|
+
import uiConfig from "./cms/ui-config.json";
|
|
13
|
+
|
|
14
|
+
// `rebase dev` injects VITE_API_URL with the port it actually bound, and that
|
|
15
|
+
// port is derived from this project's path rather than fixed — so a
|
|
16
|
+
// `http://localhost:3001` fallback here names a port nothing is listening on.
|
|
17
|
+
// A deployed build serves the admin from the same origin as the API, where an
|
|
18
|
+
// empty value is exactly what you want.
|
|
19
|
+
const API_URL = import.meta.env.VITE_API_URL;
|
|
20
|
+
const GOOGLE_CLIENT_ID = import.meta.env.VITE_GOOGLE_CLIENT_ID;
|
|
21
|
+
|
|
22
|
+
// One client for the page, created when this module loads. Inside a component,
|
|
23
|
+
// even in a `useMemo`, `<React.StrictMode>` builds a second one in development,
|
|
24
|
+
// and both restore the session and open their own connections.
|
|
25
|
+
const rebaseClient = createRebaseClient({
|
|
26
|
+
baseUrl: API_URL,
|
|
27
|
+
// Store the refresh token in an httpOnly cookie (XSS-safe) rather than
|
|
28
|
+
// localStorage. The backend issues it via `auth.cookieAuth`.
|
|
29
|
+
auth: { authFlowMode: "cookie" }
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
export function App() {
|
|
33
|
+
const authController = useRebaseAuthController({
|
|
34
|
+
client: rebaseClient,
|
|
35
|
+
googleClientId: GOOGLE_CLIENT_ID
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<ErrorBoundary fullPage>
|
|
40
|
+
<Rebase
|
|
41
|
+
client={rebaseClient}
|
|
42
|
+
authController={authController}
|
|
43
|
+
>
|
|
44
|
+
{/* The sign-in screen. On its own this changes nothing —
|
|
45
|
+
it is where you pass `loginView` to replace it. */}
|
|
46
|
+
<RebaseAuth />
|
|
47
|
+
{/* Every table the backend serves gets an admin view with no
|
|
48
|
+
code. A file in ./cms changes how one of them looks:
|
|
49
|
+
labels, icons, enum colours, custom fields and actions. */}
|
|
50
|
+
<RebaseCMS tableCustomizations={[usersCms]} uiConfig={uiConfig} />
|
|
51
|
+
<RebaseStudio/>
|
|
52
|
+
<RebaseShell title="Rebase"/>
|
|
53
|
+
</Rebase>
|
|
54
|
+
</ErrorBoundary>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { defineTable, col } from "@rebasepro/server/schema";
|
|
2
|
+
|
|
3
|
+
export const categories = defineTable("categories", {
|
|
4
|
+
columns: {
|
|
5
|
+
id: col.integer().primaryKey().generatedByDefaultAsIdentity(),
|
|
6
|
+
name: col.text().notNull(),
|
|
7
|
+
slug: col.text().notNull(),
|
|
8
|
+
description: col.text(),
|
|
9
|
+
icon: col.text()
|
|
10
|
+
},
|
|
11
|
+
rls: "inherit"
|
|
12
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { DefaultRls } from "@rebasepro/server/schema";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Every table this backend serves. A `defineTable` that is not exported from
|
|
5
|
+
* here is refused at boot and by `rebase db generate`.
|
|
6
|
+
*/
|
|
7
|
+
export { products } from "./products";
|
|
8
|
+
export { categories } from "./categories";
|
|
9
|
+
export { orders } from "./orders";
|
|
10
|
+
export { users } from "./users";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* What a table with `rls: "inherit"` gets: admins read and write, nobody else.
|
|
14
|
+
*
|
|
15
|
+
* Said out loud rather than left to `"admin-only"`, so `rebase verify` (and the
|
|
16
|
+
* reader) can tell a decision from an omission. A storefront opens tables up one
|
|
17
|
+
* at a time: `{ operation: "select", access: "public" }` on products and
|
|
18
|
+
* categories for a public catalogue, and `ownerField` on orders once they carry
|
|
19
|
+
* the customer's user id.
|
|
20
|
+
*/
|
|
21
|
+
export const defaultRls: DefaultRls = [
|
|
22
|
+
{ operation: "all", roles: ["admin"] }
|
|
23
|
+
];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { defineTable, col } from "@rebasepro/server/schema";
|
|
2
|
+
|
|
3
|
+
export const orders = defineTable("orders", {
|
|
4
|
+
columns: {
|
|
5
|
+
id: col.integer().primaryKey().generatedByDefaultAsIdentity(),
|
|
6
|
+
customerEmail: col.text().notNull(),
|
|
7
|
+
status: col.enum(["pending", "processing", "shipped", "delivered", "cancelled"]),
|
|
8
|
+
total: col.numeric().notNull(),
|
|
9
|
+
notes: col.text(),
|
|
10
|
+
createdAt: col.timestamp({ withTimezone: true }).onCreateNow()
|
|
11
|
+
},
|
|
12
|
+
rls: "inherit"
|
|
13
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { defineTable, col, rel } from "@rebasepro/server/schema";
|
|
2
|
+
import { categories } from "./categories";
|
|
3
|
+
|
|
4
|
+
export const products = defineTable("products", {
|
|
5
|
+
columns: {
|
|
6
|
+
id: col.integer().primaryKey().generatedByDefaultAsIdentity(),
|
|
7
|
+
name: col.text().notNull(),
|
|
8
|
+
description: col.text(),
|
|
9
|
+
price: col.numeric().notNull(),
|
|
10
|
+
image: col.storage({ path: "product_images/" }),
|
|
11
|
+
status: col.enum(["draft", "active", "archived"]),
|
|
12
|
+
categoryId: col.integer()
|
|
13
|
+
},
|
|
14
|
+
relations: {
|
|
15
|
+
category: rel.belongsTo(() => categories)
|
|
16
|
+
},
|
|
17
|
+
rls: "inherit"
|
|
18
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import "@fontsource/jetbrains-mono";
|
|
2
|
+
import "@fontsource-variable/inter";
|
|
3
|
+
import "@fontsource-variable/instrument-sans";
|
|
4
|
+
|
|
5
|
+
import { Rebase, RebaseAuth, useRebaseAuthController } from "@rebasepro/app";
|
|
6
|
+
import { RebaseCMS, RebaseShell } from "@rebasepro/cms";
|
|
7
|
+
import { ErrorBoundary } from "@rebasepro/ui";
|
|
8
|
+
import { RebaseStudio } from "@rebasepro/studio";
|
|
9
|
+
import { createRebaseClient } from "@rebasepro/client";
|
|
10
|
+
import { productsCms } from "./cms/products";
|
|
11
|
+
import { categoriesCms } from "./cms/categories";
|
|
12
|
+
import { ordersCms } from "./cms/orders";
|
|
13
|
+
import { usersCms } from "./cms/users";
|
|
14
|
+
// How the collection editor laid out the tables in development (labels, columns, views).
|
|
15
|
+
import uiConfig from "./cms/ui-config.json";
|
|
16
|
+
|
|
17
|
+
// `rebase dev` injects VITE_API_URL with the port it actually bound, and that
|
|
18
|
+
// port is derived from this project's path rather than fixed — so a
|
|
19
|
+
// `http://localhost:3001` fallback here names a port nothing is listening on.
|
|
20
|
+
// A deployed build serves the admin from the same origin as the API, where an
|
|
21
|
+
// empty value is exactly what you want.
|
|
22
|
+
const API_URL = import.meta.env.VITE_API_URL;
|
|
23
|
+
const GOOGLE_CLIENT_ID = import.meta.env.VITE_GOOGLE_CLIENT_ID;
|
|
24
|
+
|
|
25
|
+
// One client for the page, created when this module loads. Inside a component,
|
|
26
|
+
// even in a `useMemo`, `<React.StrictMode>` builds a second one in development,
|
|
27
|
+
// and both restore the session and open their own connections.
|
|
28
|
+
const rebaseClient = createRebaseClient({
|
|
29
|
+
baseUrl: API_URL,
|
|
30
|
+
// Store the refresh token in an httpOnly cookie (XSS-safe) rather than
|
|
31
|
+
// localStorage. The backend issues it via `auth.cookieAuth`.
|
|
32
|
+
auth: { authFlowMode: "cookie" }
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
export function App() {
|
|
36
|
+
const authController = useRebaseAuthController({
|
|
37
|
+
client: rebaseClient,
|
|
38
|
+
googleClientId: GOOGLE_CLIENT_ID
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<ErrorBoundary fullPage>
|
|
43
|
+
<Rebase
|
|
44
|
+
client={rebaseClient}
|
|
45
|
+
authController={authController}
|
|
46
|
+
>
|
|
47
|
+
{/* The sign-in screen. On its own this changes nothing —
|
|
48
|
+
it is where you pass `loginView` to replace it. */}
|
|
49
|
+
<RebaseAuth />
|
|
50
|
+
{/* Every table the backend serves gets an admin view with no
|
|
51
|
+
code. A file in ./cms changes how one of them looks:
|
|
52
|
+
labels, icons, enum colours, custom fields and actions. */}
|
|
53
|
+
<RebaseCMS tableCustomizations={[productsCms, categoriesCms, ordersCms, usersCms]} uiConfig={uiConfig} />
|
|
54
|
+
<RebaseStudio/>
|
|
55
|
+
<RebaseShell title="Rebase"/>
|
|
56
|
+
</Rebase>
|
|
57
|
+
</ErrorBoundary>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { customizeTable } from "@rebasepro/cms";
|
|
2
|
+
import type { categories } from "../../../backend/schema/categories";
|
|
3
|
+
|
|
4
|
+
export const categoriesCms = customizeTable<typeof categories>("categories", {
|
|
5
|
+
icon: "Category",
|
|
6
|
+
fieldOrder: ["id", "name", "slug", "description", "icon"],
|
|
7
|
+
fields: {
|
|
8
|
+
description: {
|
|
9
|
+
multiline: true
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { customizeTable } from "@rebasepro/cms";
|
|
2
|
+
import type { orders } from "../../../backend/schema/orders";
|
|
3
|
+
|
|
4
|
+
export const ordersCms = customizeTable<typeof orders>("orders", {
|
|
5
|
+
icon: "Receipt",
|
|
6
|
+
fields: {
|
|
7
|
+
status: {
|
|
8
|
+
enumLabels: {
|
|
9
|
+
pending: {
|
|
10
|
+
label: "Pending",
|
|
11
|
+
color: "gray"
|
|
12
|
+
},
|
|
13
|
+
processing: {
|
|
14
|
+
label: "Processing",
|
|
15
|
+
color: "blue"
|
|
16
|
+
},
|
|
17
|
+
shipped: {
|
|
18
|
+
label: "Shipped",
|
|
19
|
+
color: "orange"
|
|
20
|
+
},
|
|
21
|
+
delivered: {
|
|
22
|
+
label: "Delivered",
|
|
23
|
+
color: "green"
|
|
24
|
+
},
|
|
25
|
+
cancelled: {
|
|
26
|
+
label: "Cancelled",
|
|
27
|
+
color: "red"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
notes: {
|
|
32
|
+
multiline: true
|
|
33
|
+
},
|
|
34
|
+
createdAt: {
|
|
35
|
+
readOnly: true
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { customizeTable } from "@rebasepro/cms";
|
|
2
|
+
import type { products } from "../../../backend/schema/products";
|
|
3
|
+
|
|
4
|
+
export const productsCms = customizeTable<typeof products>("products", {
|
|
5
|
+
icon: "ShoppingCart",
|
|
6
|
+
fields: {
|
|
7
|
+
description: {
|
|
8
|
+
markdown: true
|
|
9
|
+
},
|
|
10
|
+
status: {
|
|
11
|
+
enumLabels: {
|
|
12
|
+
draft: {
|
|
13
|
+
label: "Draft",
|
|
14
|
+
color: "gray"
|
|
15
|
+
},
|
|
16
|
+
active: {
|
|
17
|
+
label: "Active",
|
|
18
|
+
color: "green"
|
|
19
|
+
},
|
|
20
|
+
archived: {
|
|
21
|
+
label: "Archived",
|
|
22
|
+
color: "orange"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$generated": "Generated from
|
|
2
|
+
"$generated": "Generated from backend/resources.ts and backend/schema by `rebase resources`. Edit the declarations, not this file.",
|
|
3
3
|
"version": 1,
|
|
4
4
|
"resources": [
|
|
5
5
|
{
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"engine": "postgres",
|
|
9
9
|
"transport": "server",
|
|
10
10
|
"usedBy": [
|
|
11
|
-
"
|
|
11
|
+
"table:users"
|
|
12
12
|
]
|
|
13
13
|
},
|
|
14
14
|
{
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$generated": "Generated from
|
|
2
|
+
"$generated": "Generated from backend/resources.ts and backend/schema by `rebase resources`. Edit the declarations, not this file.",
|
|
3
3
|
"version": 1,
|
|
4
4
|
"resources": [
|
|
5
5
|
{
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
"engine": "postgres",
|
|
9
9
|
"transport": "server",
|
|
10
10
|
"usedBy": [
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
11
|
+
"table:authors",
|
|
12
|
+
"table:posts",
|
|
13
|
+
"table:tags",
|
|
14
|
+
"table:users"
|
|
15
15
|
]
|
|
16
16
|
},
|
|
17
17
|
{
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$generated": "Generated from
|
|
2
|
+
"$generated": "Generated from backend/resources.ts and backend/schema by `rebase resources`. Edit the declarations, not this file.",
|
|
3
3
|
"version": 1,
|
|
4
4
|
"resources": [
|
|
5
5
|
{
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
"engine": "postgres",
|
|
9
9
|
"transport": "server",
|
|
10
10
|
"usedBy": [
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
11
|
+
"table:categories",
|
|
12
|
+
"table:orders",
|
|
13
|
+
"table:products",
|
|
14
|
+
"table:users"
|
|
15
15
|
]
|
|
16
16
|
},
|
|
17
17
|
{
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$generated": "Generated from
|
|
2
|
+
"$generated": "Generated from backend/resources.ts and backend/schema by `rebase resources`. Edit the declarations, not this file.",
|
|
3
3
|
"version": 1,
|
|
4
4
|
"resources": [
|
|
5
5
|
{
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
# Rebase guardrail for Claude Code, installed by `rebase init` and `rebase skills --hooks`.
|
|
3
3
|
#
|
|
4
|
-
# After Claude Code edits a
|
|
5
|
-
#
|
|
6
|
-
# `rebase verify --quiet` and hands any
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
#
|
|
10
|
-
#
|
|
4
|
+
# After Claude Code edits a table — a file under backend/schema/, or the
|
|
5
|
+
# directory rebase.json names in `apps.<backend>.tables` — or a customization
|
|
6
|
+
# under frontend/src/cms/, this runs `rebase verify --quiet` and hands any
|
|
7
|
+
# problem straight back to the agent: a table the server would refuse, a `rls`
|
|
8
|
+
# that does not compile, a migration the tables have moved past. Exit code 2 is
|
|
9
|
+
# how a PostToolUse hook talks to the agent: Claude Code shows it what this
|
|
10
|
+
# prints on stderr, and the agent fixes it before going on.
|
|
11
|
+
#
|
|
12
|
+
# The file keeps the name it shipped with (post-edit-collection.sh): it is the
|
|
13
|
+
# name `rebase skills --hooks` recognises in a project that already has it, and
|
|
14
|
+
# the name its settings entry points at.
|
|
11
15
|
#
|
|
12
16
|
# Edits anywhere else return at once. Safe to delete; `rebase skills --hooks`
|
|
13
17
|
# puts it back.
|
|
@@ -16,19 +20,19 @@ set -u
|
|
|
16
20
|
input="$(cat)"
|
|
17
21
|
|
|
18
22
|
# The edited file, from the tool call Claude Code passes on stdin, and the
|
|
19
|
-
#
|
|
20
|
-
#
|
|
23
|
+
# tables directory, from rebase.json (`apps.<backend>.tables`, by default
|
|
24
|
+
# `backend/schema`) — the runtime and `rebase verify` read the tables from
|
|
21
25
|
# there, so a project that moved them is still checked. Node rather than jq:
|
|
22
26
|
# every Rebase project has Node, not every machine has jq.
|
|
23
27
|
parsed="$(printf '%s' "$input" | node -e '
|
|
24
28
|
let raw = "";
|
|
25
29
|
process.stdin.on("data", chunk => { raw += chunk; });
|
|
26
30
|
process.stdin.on("end", () => {
|
|
27
|
-
let
|
|
31
|
+
let tables = "backend/schema";
|
|
28
32
|
try {
|
|
29
33
|
const manifest = JSON.parse(require("fs").readFileSync(require("path").join(process.env.CLAUDE_PROJECT_DIR || ".", "rebase.json"), "utf8"));
|
|
30
34
|
const backend = Object.values(manifest.apps || {}).find(app => app && app.type === "backend");
|
|
31
|
-
if (backend && typeof backend.
|
|
35
|
+
if (backend && typeof backend.tables === "string" && backend.tables) tables = backend.tables.replace(/\\/g, "/").replace(/^\.\//, "").replace(/\/+$/, "");
|
|
32
36
|
} catch {
|
|
33
37
|
// No rebase.json, or one this cannot read: the conventional layout.
|
|
34
38
|
}
|
|
@@ -36,19 +40,19 @@ process.stdin.on("end", () => {
|
|
|
36
40
|
try {
|
|
37
41
|
const toolInput = JSON.parse(raw).tool_input || {};
|
|
38
42
|
// Forward slashes on every OS: on Windows the path arrives as
|
|
39
|
-
// C:\Users\me\shop\
|
|
43
|
+
// C:\Users\me\shop\backend\schema\posts.ts, which the case below never matched.
|
|
40
44
|
file = String(toolInput.file_path || toolInput.notebook_path || "").replace(/\\/g, "/");
|
|
41
45
|
} catch {
|
|
42
46
|
// Not a tool call this hook understands: nothing to check.
|
|
43
47
|
}
|
|
44
|
-
process.stdout.write(
|
|
48
|
+
process.stdout.write(tables + "\n" + file);
|
|
45
49
|
});
|
|
46
50
|
')"
|
|
47
|
-
|
|
51
|
+
tables_dir="${parsed%%$'\n'*}"
|
|
48
52
|
file="${parsed#*$'\n'}"
|
|
49
53
|
|
|
50
54
|
case "$file" in
|
|
51
|
-
*/"$
|
|
55
|
+
*/"$tables_dir"/* | "$tables_dir"/* | */frontend/src/cms/* | frontend/src/cms/*) ;;
|
|
52
56
|
*) exit 0 ;;
|
|
53
57
|
esac
|
|
54
58
|
|
|
@@ -57,12 +61,12 @@ cd "${CLAUDE_PROJECT_DIR:-.}" || exit 0
|
|
|
57
61
|
# The project's own CLI, pinned with the rest of its @rebasepro packages.
|
|
58
62
|
#
|
|
59
63
|
# Not installed yet is the state `rebase init --yes` leaves, and it is not a
|
|
60
|
-
# problem in the
|
|
64
|
+
# problem in the schema the agent just edited, so it never blocks the
|
|
61
65
|
# edit. There is no `npx` fallback: `npx --no rebase` with nothing installed
|
|
62
66
|
# exits 1 ("could not determine executable to run"), which read as a failed
|
|
63
|
-
# verify and told the agent to fix
|
|
67
|
+
# verify and told the agent to fix tables that were fine.
|
|
64
68
|
if [ ! -x node_modules/.bin/rebase ]; then
|
|
65
|
-
echo "Rebase guardrail skipped: this project's dependencies are not installed (no node_modules/.bin/rebase). Run the install — pnpm install, or your package manager's — to check
|
|
69
|
+
echo "Rebase guardrail skipped: this project's dependencies are not installed (no node_modules/.bin/rebase). Run the install — pnpm install, or your package manager's — to check the schema after each edit." >&2
|
|
66
70
|
exit 0
|
|
67
71
|
fi
|
|
68
72
|
output="$(node_modules/.bin/rebase verify --quiet 2>&1)"
|
|
@@ -74,16 +78,16 @@ fi
|
|
|
74
78
|
|
|
75
79
|
# A project pinned to a CLI from before `rebase verify` answers "Unknown
|
|
76
80
|
# command", and a CLI whose interpreter is missing cannot run at all (127).
|
|
77
|
-
# Neither is a problem in the
|
|
81
|
+
# Neither is a problem in the schema the agent just edited, so neither
|
|
78
82
|
# blocks the edit: say why the check was skipped, and go on.
|
|
79
83
|
case "$output" in
|
|
80
84
|
*"Unknown command"*verify*)
|
|
81
|
-
echo "Rebase guardrail skipped: this project's @rebasepro/cli predates \`rebase verify\`. Upgrade it with \`rebase upgrade\` to check
|
|
85
|
+
echo "Rebase guardrail skipped: this project's @rebasepro/cli predates \`rebase verify\`. Upgrade it with \`rebase upgrade\` to check the schema after each edit." >&2
|
|
82
86
|
exit 0
|
|
83
87
|
;;
|
|
84
88
|
esac
|
|
85
89
|
if [ "$status" -eq 127 ]; then
|
|
86
|
-
echo "Rebase guardrail skipped: this project's rebase CLI could not be run. Reinstall the dependencies to check
|
|
90
|
+
echo "Rebase guardrail skipped: this project's rebase CLI could not be run. Reinstall the dependencies to check the schema after each edit." >&2
|
|
87
91
|
exit 0
|
|
88
92
|
fi
|
|
89
93
|
|
|
@@ -93,7 +97,7 @@ fi
|
|
|
93
97
|
echo ""
|
|
94
98
|
echo "$output"
|
|
95
99
|
echo ""
|
|
96
|
-
echo "Each problem names its file, the
|
|
97
|
-
echo "Fix them in ${
|
|
100
|
+
echo "Each problem names its file, the table and column, and the fix."
|
|
101
|
+
echo "Fix them in ${tables_dir}/ or frontend/src/cms/ before moving on; run \`rebase verify\` for the full report."
|
|
98
102
|
} >&2
|
|
99
103
|
exit 2
|
|
@@ -6,8 +6,8 @@ The Rebase skills for this assistant live in `.cursor/rules/`. If they are not t
|
|
|
6
6
|
|
|
7
7
|
These hold before you have opened ai-instructions.md, and in every session:
|
|
8
8
|
|
|
9
|
-
- **A table is a
|
|
10
|
-
- **Data goes through the SDK:** `rebase.dataAsAdmin.<
|
|
9
|
+
- **A table is a file in `backend/schema/`.** Declare it with `defineTable` from `@rebasepro/server/schema` — columns, relations and a required `rls` — export it from `backend/schema/index.ts`, and `pnpm dev` creates it. How it looks in the admin panel is a separate, optional file: `frontend/src/cms/<table>.tsx` with `customizeTable`, which imports the table as a type only. Never `CREATE TABLE`, `ALTER TABLE` or `CREATE INDEX` in code, and never SQL as the database owner against an application table: `rebase.sql()` skips row-level security, validation and hooks, so keep it for server work that needs every row and for reading a column marked `.private()`. When the SDK cannot express a query, run it as the caller with `getSql(c)` — the same row-level security as the SDK, read-only unless `{ write: true }`, every value in `params`. A table that already exists gets its file from `pnpm schema:introspect`. With no `backend/schema/` (a headless project) the database is the schema instead: ai-instructions.md says how to serve a table.
|
|
10
|
+
- **Data goes through the SDK:** `rebase.dataAsAdmin.<table>` in functions and crons, `getDriver(c)` to act as the caller.
|
|
11
11
|
- **A route in `backend/functions/` is public until you guard it** with `requireAuth` or `requireAdmin` from `@rebasepro/server/functions`.
|
|
12
12
|
- **Never deploy, never edit `.env`, never edit generated files** (`backend/src/schema.generated.ts`, `rebase.resources.json`).
|
|
13
13
|
- **When Rebase cannot do what the task needs, tell the human** what is missing instead of working around it.
|