@protobase/cli 0.49.1 → 0.50.0
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/bin/protobase.mjs +3 -2
- package/dist/build/config-bundle.js +1 -1
- package/dist/build/deploy-bundle.js +3 -4
- package/dist/build/plugin-build.js +16 -8
- package/dist/build/plugin-fields.js +5 -2
- package/dist/build/ui-check.js +5 -0
- package/dist/build/view-check.js +1 -1
- package/dist/cli/package.js +1 -1
- package/dist/config/build-project.js +13 -6
- package/dist/config/project-files.js +4 -1
- package/dist/config/read-config.js +5 -1
- package/dist/config/source-config.js +1 -1
- package/dist/db/read-only-db.js +1 -1
- package/dist/dev/api-process.js +1 -1
- package/dist/dev/app-server.js +43 -35
- package/dist/dev/create-db.js +2 -2
- package/dist/dev/dev-jobs.js +5 -3
- package/dist/dev/entry.js +3 -3
- package/dist/dev/project.js +3 -2
- package/dist/dev/server-package.js +9 -21
- package/dist/doctor/run.js +1 -1
- package/dist/hand-over.d.ts +15 -0
- package/dist/hand-over.js +32 -0
- package/dist/main.js +22 -5
- package/dist/migration/load-project.js +1 -1
- package/dist/project/bundled-imports.js +41 -0
- package/dist/project/import-project-file.js +28 -8
- package/dist/project/load-bundle-project.js +1 -1
- package/dist/project/load-data-config.js +4 -3
- package/dist/project/project-types.js +66 -0
- package/dist/project-auth.d.ts +2 -0
- package/dist/project-auth.js +2 -0
- package/dist/run/preload.d.ts +1 -0
- package/dist/run/preload.js +20 -0
- package/dist/run/run-script.js +36 -0
- package/dist/serve/app.js +1 -1
- package/dist/serve/create-admin.js +1 -1
- package/dist/serve/host-modules.js +3 -3
- package/dist/serve/lifecycle.js +4 -3
- package/dist/supabase/load-phase.js +6 -5
- package/dist/users/load-auth.d.ts +10 -0
- package/dist/users/load-auth.js +1 -1
- package/dist/version/project-packages.js +39 -0
- package/dist/version/project-version.js +33 -12
- package/dist/worker/start-worker.js +3 -2
- package/package.json +10 -8
- package/skills/protobase/SKILL.md +1 -1
- package/skills/protobase/references/features/build-and-run.md +3 -0
- package/skills/protobase/references/features/events-webhooks-and-jobs.md +1 -0
- package/skills/protobase/references/features/files-and-images.md +1 -0
- package/skills/protobase/references/features/releases.md +2 -1
- package/skills/protobase/references/features/sign-in-and-accounts.md +1 -0
- package/skills/protobase/references/features/start-a-project.md +1 -1
- package/skills/protobase/references/getting-started.md +18 -5
- package/skills/protobase/references/guides/api-functions.md +1 -1
- package/skills/protobase/references/guides/billing-page.md +4 -4
- package/skills/protobase/references/guides/create-page.md +2 -2
- package/skills/protobase/references/guides/deploy.md +24 -8
- package/skills/protobase/references/guides/field-type.md +1 -1
- package/skills/protobase/references/guides/first-plugin.md +1 -1
- package/skills/protobase/references/guides/plugin-build.md +1 -1
- package/skills/protobase/references/guides/remote-resources.md +1 -1
- package/skills/protobase/references/guides/table-to-admin.md +8 -8
- package/skills/protobase/references/reference/ai.md +1 -1
- package/skills/protobase/references/reference/api.md +4 -4
- package/skills/protobase/references/reference/architecture.md +11 -6
- package/skills/protobase/references/reference/assistant.md +1 -1
- package/skills/protobase/references/reference/auth.md +24 -6
- package/skills/protobase/references/reference/blocks.md +1 -1
- package/skills/protobase/references/reference/bottom-bar.md +2 -2
- package/skills/protobase/references/reference/cli.md +51 -22
- package/skills/protobase/references/reference/client.md +3 -1
- package/skills/protobase/references/reference/config/api.md +2 -2
- package/skills/protobase/references/reference/config/app.md +2 -2
- package/skills/protobase/references/reference/config/sign-in.md +3 -4
- package/skills/protobase/references/reference/config.md +13 -10
- package/skills/protobase/references/reference/custom-components.md +3 -2
- package/skills/protobase/references/reference/email.md +5 -5
- package/skills/protobase/references/reference/events.md +1 -1
- package/skills/protobase/references/reference/files.md +6 -3
- package/skills/protobase/references/reference/jobs.md +20 -10
- package/skills/protobase/references/reference/layouts.md +2 -2
- package/skills/protobase/references/reference/mcp.md +9 -8
- package/skills/protobase/references/reference/notifications.md +10 -8
- package/skills/protobase/references/reference/plugins.md +3 -3
- package/skills/protobase/references/reference/ui-config.md +1 -1
- package/skills/protobase/references/reference/user-menu.md +3 -3
- package/skills/protobase/references/reference/versioning.md +21 -4
- package/skills/protobase/references/reference/webhooks.md +5 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.50.0",
|
|
4
4
|
"description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -13,12 +13,14 @@
|
|
|
13
13
|
"sideEffects": [
|
|
14
14
|
"./dist/dev/entry.js",
|
|
15
15
|
"./dist/dev/api-process.js",
|
|
16
|
-
"./dist/serve/main.js"
|
|
16
|
+
"./dist/serve/main.js",
|
|
17
|
+
"./dist/run/preload.js"
|
|
17
18
|
],
|
|
18
19
|
"engines": {
|
|
19
20
|
"node": ">=22.12.0"
|
|
20
21
|
},
|
|
21
22
|
"exports": {
|
|
23
|
+
"./auth": "./dist/project-auth.js",
|
|
22
24
|
"./runner": "./dist/runner.js"
|
|
23
25
|
},
|
|
24
26
|
"bin": {
|
|
@@ -39,12 +41,12 @@
|
|
|
39
41
|
"dependencies": {
|
|
40
42
|
"@better-auth/core": "^1.7.12",
|
|
41
43
|
"@hono/node-server": "^2.1.3",
|
|
42
|
-
"@protobase/config": "0.
|
|
43
|
-
"@protobase/layout": "0.
|
|
44
|
-
"@protobase/query": "0.
|
|
45
|
-
"@protobase/schema": "0.
|
|
46
|
-
"@protobase/server": "0.
|
|
47
|
-
"@protobase/ui": "0.
|
|
44
|
+
"@protobase/config": "0.50.0",
|
|
45
|
+
"@protobase/layout": "0.50.0",
|
|
46
|
+
"@protobase/query": "0.50.0",
|
|
47
|
+
"@protobase/schema": "0.50.0",
|
|
48
|
+
"@protobase/server": "0.50.0",
|
|
49
|
+
"@protobase/ui": "0.50.0",
|
|
48
50
|
"@react-email/render": "^2.1.0",
|
|
49
51
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
50
52
|
"@tailwindcss/vite": "^4.3.3",
|
|
@@ -11,7 +11,7 @@ Run the CLI as the project does: `npx protobase <command>`, or `bun run protobas
|
|
|
11
11
|
|
|
12
12
|
## Everyday workflow
|
|
13
13
|
|
|
14
|
-
1. Run `protobase dev`: one
|
|
14
|
+
1. Run `protobase dev`: one port for the admin app and the API, which runs in a process of its own; changes to config, layouts and functions show without a restart.
|
|
15
15
|
2. Change the config (`data.ts`, `ui.ts`, layouts) or the app's code.
|
|
16
16
|
3. Database changes go through the project's migrations, never through startup: `protobase migration` writes the migrations a config feature needs, the project applies them with its own migrate script. See [references/reference/cli.md](references/reference/cli.md#migration).
|
|
17
17
|
|
|
@@ -6,6 +6,8 @@ Develop, build and run an app, on servers, in containers and on phones.
|
|
|
6
6
|
|
|
7
7
|
- [Node and Bun](../reference/cli.md#how-it-runs): The `protobase` command runs on Node 22.12 or later or on Bun, and a bundle runs on both unless it is built for Bun only.
|
|
8
8
|
- [Dev server](../reference/cli.md#dev): The admin app and the API on one port, with changes shown without a restart.
|
|
9
|
+
- [Editor types](../reference/cli.md#types): `protobase types` gives the editor and `tsc` the types of the CLI that builds the app, with nothing installed.
|
|
10
|
+
- [Project scripts](../reference/cli.md#run): `protobase run` runs a seed or a migration script on the CLI's packages.
|
|
9
11
|
- [Migrations from config](../reference/cli.md#migration): Writes the SQL migrations for what the config turns on, as files of the project.
|
|
10
12
|
- [User and organization commands](../reference/cli.md#users): Create users, set roles and manage organizations from the terminal.
|
|
11
13
|
- [Encryption commands](../reference/cli.md#encryption-status): Report and fix plaintext or old-key values of encrypted fields.
|
|
@@ -19,4 +21,5 @@ Develop, build and run an app, on servers, in containers and on phones.
|
|
|
19
21
|
- [Separate worker](../reference/cli.md#worker): Jobs and event delivery in their own process.
|
|
20
22
|
- [Container images](../guides/deploy.md#images): A runtime image for each release, for amd64 and arm64.
|
|
21
23
|
- [Self-hosted image](../guides/deploy.md#a-self-hosted-image): One image with the app inside that serves, migrates and creates the first admin.
|
|
24
|
+
- [Protobase Cloud deploys](../guides/deploy.md#protobase-cloud): A push to the app's GitHub branch builds it, migrates and checks its database in one transaction, and switches to the new version once it answers its health check.
|
|
22
25
|
- [Mobile apps](../guides/mobile-app.md) (beta): Runs an app on iOS and Android, also on your own iPhone, with sign-in, and builds signed store releases from a section in its config.
|
|
@@ -11,6 +11,7 @@ React to changes, deliver them to other systems, and run work in the background.
|
|
|
11
11
|
- [Delivery retries](../reference/webhooks.md#delivery-and-retries): Failed deliveries are retried for about three days.
|
|
12
12
|
- [Webhooks in the admin app](../reference/webhooks.md#subscriptions-in-the-admin-app): Users create subscriptions, send test events and resend failures in the app.
|
|
13
13
|
- [Background jobs](../reference/jobs.md#enqueueing): Jobs are kept in the app's own Postgres and can be queued in the same transaction as a write, also from SQL.
|
|
14
|
+
- [Typed jobs](../reference/jobs.md#typed-names-and-payloads): Code that queues a job, and the job itself, are checked against the names and arguments the config declares as they compile.
|
|
14
15
|
- [Retries](../reference/jobs.md#failures): Failed jobs are retried with growing waits, and duplicates can be prevented with a key.
|
|
15
16
|
- [Ordered groups](../reference/jobs.md#ordered-groups): Jobs in one group run one at a time, in order.
|
|
16
17
|
- [Recurring jobs](../reference/jobs.md#recurring-jobs): Jobs run on a cron schedule in a chosen time zone.
|
|
@@ -7,6 +7,7 @@ Uploaded files and images, where they are kept and how they are served.
|
|
|
7
7
|
- [File fields](../reference/files.md#what-the-column-holds): A text column holds an uploaded file, with limits on type and size.
|
|
8
8
|
- [File storage](../reference/files.md#providers): Files are kept on disk, or in a bucket of your own.
|
|
9
9
|
- [S3-compatible buckets](../reference/files.md#s3-compatible-buckets) (beta): Files are kept in any bucket that speaks the S3 API, when the app runs on Bun.
|
|
10
|
+
- [Files from a seed](../reference/files.md#writing-files-from-a-seed): A seed or another script writes files into the app's providers, read from its config and environment as the server reads them.
|
|
10
11
|
- [Type detection](../reference/files.md#how-the-type-is-decided): An upload's type is decided from its content, and a disguised file is refused.
|
|
11
12
|
- [Signed downloads](../reference/files.md#downloads): Private files open through short-lived links that stop working once the record no longer holds the file.
|
|
12
13
|
- [Derived fields](../reference/files.md#derived-fields): Width, height, size and type of each upload are written to other fields.
|
|
@@ -6,7 +6,8 @@ How Protobase is released and versioned, and what a release keeps working.
|
|
|
6
6
|
|
|
7
7
|
- [Releases](../reference/versioning.md#releases): Every fix and feature is released when it lands, as npm packages, published with provenance, and images of one version.
|
|
8
8
|
- [Version rules](../reference/versioning.md#versions-below-10): Semantic versioning. Below 1.0 a minor version may break.
|
|
9
|
-
- [
|
|
9
|
+
- [Bundled and locked projects](../reference/versioning.md#bundled-and-locked-projects): A project that lists the `@protobase` packages as dev dependencies, or not at all, runs on the CLI's own and updates with a newer CLI, with nothing of Protobase installed. Listed as dependencies, they lock it to one version.
|
|
10
|
+
- [Bundles and runtimes](../reference/versioning.md#bundles-and-runtimes): The CLI runs every project whose version specifier holds its own version, and a bundle names the version it was built with, for the host to serve it on.
|
|
10
11
|
- [Plugins keep working](../reference/versioning.md#plugins): Plugins target a plugin API that releases keep.
|
|
11
12
|
- [Runtime updates](../reference/versioning.md#runtime-updates): Admins see whether the runtime has an update and start it from the app, when the host offers one.
|
|
12
13
|
- [New version notice](../reference/versioning.md#a-new-version-under-an-open-page): An open page keeps working when the server moves to a new Protobase version, and offers a reload.
|
|
@@ -6,6 +6,7 @@ Sign-in methods, users, roles, organizations and tokens.
|
|
|
6
6
|
|
|
7
7
|
- [Built-in sign-in](../reference/auth.md): Password sign-in, sessions and short-lived tokens, with no separate identity service.
|
|
8
8
|
- [First admin](../reference/auth.md#first-run): No account can be made over the web while the app has no users. You create the first admin from the terminal, and the last active admin cannot be deleted, demoted or blocked.
|
|
9
|
+
- [Users from a script](../reference/auth.md#first-run): A seed or another script of the project creates and lists users, and mints their tokens, on the app's own sign-in.
|
|
9
10
|
- [Versioned sign-in tables](../reference/auth.md#migrations): The sign-in tables come from numbered migrations that ship with Protobase, written as the project's own and recorded in the database, so a deploy checks them without comparing tables. Every feature has its tables from the start, so turning one on or off needs no migration.
|
|
10
11
|
- [Existing users table](../reference/auth.md#an-existing-users-table): Sign-in can use the users table another system keeps in the same database.
|
|
11
12
|
- [Users page](../reference/auth.md#users-page): Admins find people, set roles, block them, add accounts and invite people by email.
|
|
@@ -8,7 +8,7 @@ Start a new app, or an admin over an existing Postgres database, and keep the co
|
|
|
8
8
|
- [Example apps](../getting-started.md#run-the-erp-example): Seeded example apps on Postgres: an ERP, real estate property management and a public property portal.
|
|
9
9
|
- [One config](../reference/config.md): The whole app is one object of data in `protobase.config.ts`, typed with `defineConfig`, with a sensible default for every key.
|
|
10
10
|
- [Code found by path](../reference/config.md#where-the-code-is): The config names jobs, hooks and providers, and Protobase finds their code by its path, such as `jobs/<name>.ts`.
|
|
11
|
-
- [JSON config](../reference/config.md#the-same-config-as-json): The same config works as `protobase.config.json`, with values from the environment written as `$env
|
|
11
|
+
- [JSON config](../reference/config.md#the-same-config-as-json): The same config works as `protobase.config.json`, with values from the environment written as `$env`, and a JSON Schema that checks it in the editor.
|
|
12
12
|
- [App options](../reference/config/app.md): The app's name, public URL, secret, language, time zone, install colours and mobile build, each with its type, default and environment variable.
|
|
13
13
|
- [Sign-in options](../reference/config/sign-in.md): Every key of `auth` and `authenticate`, from roles and organizations to sign-in providers and tokens of an auth server elsewhere.
|
|
14
14
|
- [API options](../reference/config/api.md): The REST API's path, keys, CORS, access defaults, query limits, error reporting, write hooks and MCP tools.
|
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
|
|
5
5
|
Start an app with npm create protobase, install the repository, run the ERP, real estate and property portal examples and learn the development commands.
|
|
6
6
|
|
|
7
|
-
Protobase is a config-driven admin panel framework for existing Postgres databases.
|
|
7
|
+
Protobase is a config-driven admin panel framework for existing Postgres databases. Each resource's data config lives in `config/<resource>/data.ts` and its UI config in `ui.ts`, all exported from `config/index.ts`; the rest of the app, its sign-in, jobs, files and API settings, is one object of data in [`protobase.config.ts`](reference/config.md). A Hono server serves the API and a React app renders the admin. Coding agents get the guides and reference of the installed version with [`protobase skill install`](reference/cli.md#skill).
|
|
8
8
|
|
|
9
9
|
An app's own React code, its components, field types and actions, is a [plugin](reference/plugins.md): built on its own against a plugin API that Protobase's releases keep, and loaded by the admin app when it starts. Protobase maintains the admin app, the API and the server, and a plugin keeps working as the app moves to newer releases, with their fixes and features, without changes of its own. Below 1.0 a new minor version may still change the config, and the bundle is built again for it; the plugins' code stays as it is (see [Who maintains what](reference/plugins.md#who-maintains-what)).
|
|
10
10
|
|
|
11
11
|
## Start an app
|
|
12
12
|
|
|
13
|
-
`npm create protobase my-app` asks which preset to start from, scratch (the default), the ERP or real estate, writes the project into `my-app`, with the `@protobase` packages in the range of the latest release's
|
|
13
|
+
`npm create protobase my-app` asks which preset to start from, scratch (the default), the ERP or real estate, writes the project into `my-app`, with the `@protobase` packages in `devDependencies` at the caret range of the latest release, so it is [bundled](reference/versioning.md#bundled-and-locked-projects): dev, the build and its scripts run the CLI's own copies, and a newer CLI in that range updates it with no change to its files. It prints the next steps. Without a folder it asks for one too. `--preset <name>` picks the preset without asking; without a terminal it takes scratch. `bun create protobase` and `pnpm create protobase` do the same, and take `--preset` without the `--` that npm needs. It needs Node 22.12 or later. Each preset has an `AGENTS.md` with the rules for a coding agent that changes the app, such as a new migration file for every schema change.
|
|
14
14
|
|
|
15
15
|
```sh
|
|
16
16
|
npm create protobase my-app
|
|
@@ -28,6 +28,19 @@ bun run protobase users create you@example.com --generate-password
|
|
|
28
28
|
bun run dev # http://localhost:5173
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
+
### The first table
|
|
32
|
+
|
|
33
|
+
A scratch app starts without resources, so `protobase doctor` refuses it until it has one. A table comes in through a migration, the next file in `db/migrations/`, and `scaffold` writes its resource from the database:
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
# db/migrations/007_customers.sql: create table customers (id bigint generated always as identity primary key, name text not null);
|
|
37
|
+
bun run db:migrate
|
|
38
|
+
bun run protobase scaffold --ui --yes --exclude public.schema_migrations
|
|
39
|
+
bun run protobase doctor
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
`scaffold` writes `config/customers/data.ts` and `ui.ts` and exports them from `config/index.ts`, where Protobase finds every resource, view and page; `--exclude public.schema_migrations` leaves out the table the migrate script records its migrations in. `bun run dev` shows the new list at once. The [Data config](reference/data-config.md) and [UI config](reference/ui-config.md) say what else a resource can be.
|
|
43
|
+
|
|
31
44
|
## Admin over an existing database
|
|
32
45
|
|
|
33
46
|
For a Postgres database you already have, [Admin over an existing database](guides/existing-database.md) goes from an empty folder to signing in: install the packages, scaffold the config from the tables, check it with `doctor`, add sign-in and its tables, create the first admin and run `protobase dev`.
|
|
@@ -88,14 +101,14 @@ bun run --cwd tests/apps/property-portal dev # http://localhost:517
|
|
|
88
101
|
| `bun run test:watch` | `bun run test` in watch mode |
|
|
89
102
|
| `bun run test:integration` | the database, subprocess and build tests (projects `integration*`), against the Postgres container, among them the real-Postgres tests (`*.postgres.test.ts`) |
|
|
90
103
|
| `bun run test:smoke` / `node --run test:smoke` | the CLI on Bun or on Node builds the ERP and serves its bundle, whose `€` must come back intact; part of `test:integration` on Bun |
|
|
91
|
-
| `bun run presets:write <version> <dir>` | writes each preset to `<dir>/<name>`: a standalone copy of its example with the `@protobase` packages in the caret range of `<version>` (`^x.y.z`, which below 1.0 covers only that minor) and its own `bun.lock` at exactly `<version>`, which must be on npm |
|
|
104
|
+
| `bun run presets:write <version> <dir>` | writes each preset to `<dir>/<name>`: a standalone copy of its example with the `@protobase` packages in `devDependencies`, bundled, in the caret range of `<version>` (`^x.y.z`, which below 1.0 covers only that minor) and its own `bun.lock` at exactly `<version>`, which must be on npm |
|
|
92
105
|
| `bun run images:context` | the build contexts of the `protobase` and `protobase-dev` images in `dist/images`, at the version in `package.json` (see [Deploy](guides/deploy.md#images)) |
|
|
93
106
|
| `bun run test:presets` | writes each preset as `bun run presets:write` does it and installs it with Bun from npm (so at a published version), then migrates, seeds, checks, tests and builds it on a database of its own, as a role without superuser rights; needs the Postgres container |
|
|
94
107
|
| `bun run test:postgres` | the Postgres suite in `tests/postgres/` (Vitest project `postgres`): the ERP's medium seed and the planner's statistics on it, and the jobs and event delivery through PgBouncer; needs the Postgres and PgBouncer containers and `bun run test:db postgres` |
|
|
95
108
|
| `bun run test:db` | builds the template databases the database tests clone for each run (`protobase_test_template`, `real_estate_test_template`, `property_portal_test_template`, all at small scale, and the empty, auth and jobs `snapshot_*_test_template` the real-Postgres and end-to-end tests clone), when missing or older than what they are built from; without them those tests skip. `bun run test:db postgres` builds the Postgres suite's (`protobase_medium_test_template`, the ERP at medium scale), `bun run test:db snapshots` the ones `test:record` records on (`snapshot_*_test_template`). Tests never use the `protobase`, `real_estate` or `property_portal` databases |
|
|
96
109
|
| `bun run typecheck` | `tsc --noEmit` |
|
|
97
110
|
| `bun run check:boundaries` | dependency-cruiser package rules |
|
|
98
|
-
| `bun run check` | typecheck
|
|
111
|
+
| `bun run check` | typecheck, the unit, snapshot, integration and end-to-end tests a change affects (all of them without `CHECK_BASE`), and check:boundaries |
|
|
99
112
|
| `bun run storybook` | Storybook on port 6006 |
|
|
100
113
|
| `bun run build-storybook` | static Storybook build; its toolbar switches every story between light and dark |
|
|
101
114
|
| `bun run screenshots` / `bun run screenshots:dark` | screenshots of the stories tagged `website`, in light into `screenshots/`, in dark into `screenshots/dark/` |
|
|
@@ -105,4 +118,4 @@ bun run --cwd tests/apps/property-portal dev # http://localhost:517
|
|
|
105
118
|
| `bun run release --dry-run` | the next version and its changelog, from the commits since the last release (see [Versioning](reference/versioning.md)) |
|
|
106
119
|
| `bun run docs:check` | opens every page of the built site in Chromium and fails on console errors and failed requests; `BASE=https://docs.protobase.net` checks the live site |
|
|
107
120
|
|
|
108
|
-
Each public import is a package in `packages/` (`@protobase/schema`, `layout`, `query`, `client`, `ui`, `server`, and `cli` for the `protobase` command); `packages/presets` writes the projects a new app starts from and is not published; `packages/create-protobase` is `npm create protobase`, with every preset. See [Architecture](reference/architecture.md) for the layout and import rules.
|
|
121
|
+
Each public import is a package in `packages/` (`@protobase/schema`, `layout`, `query`, `client`, `ui`, `server`, `config` for `protobase.config.ts`, `mobile` for `protobase mobile`, and `cli` for the `protobase` command); `packages/presets` writes the projects a new app starts from and is not published; `packages/create-protobase` is `npm create protobase`, with every preset. See [Architecture](reference/architecture.md) for the layout and import rules.
|
|
@@ -402,7 +402,7 @@ export default defineFunction({ longQueries: true }, async (request, { db }) =>
|
|
|
402
402
|
```
|
|
403
403
|
|
|
404
404
|
- **Up to 30 seconds** per query, the most any query of an app may run. Work longer than that belongs in steps, such as a [job](../reference/jobs.md) per batch, which takes `longQueries` too.
|
|
405
|
-
- **One connection kept for it.** Under `protobase dev` and `serve`, those queries run on a connection of their own, which asks for the longer timeout when it logs in, so long work never takes the connections pages need; a second long call waits for it. A PgBouncer of your own in front of the database must list `statement_timeout` in `track_extra_parameters` to pass that on; Protobase Cloud's does.
|
|
405
|
+
- **One connection kept for it.** Under `protobase dev` and `serve`, those queries run on a connection of their own, which asks for the longer timeout when it logs in, so long work never takes the connections pages need; a second long call waits for it. A PgBouncer of your own in front of the database must list `statement_timeout` in `track_extra_parameters` to pass that on; Protobase Cloud's does.
|
|
406
406
|
- **`records` keep the API's limit,** [`statementTimeoutMs`](../reference/api.md#safety).
|
|
407
407
|
- **A query past its limit** is stopped, and the call answers `504 statement-timeout` naming the call, its limit and the way out, such as `POST /api/functions/import ran a query longer than the database's statement timeout, so the database stopped it. Make the query faster, such as with an index or a narrower filter, or give it longQueries: true, whose queries may run up to 30 s.` It goes to the app's error hook, `hooks/error.ts`, and the [error tracker](../reference/api.md#error-reporting).
|
|
408
408
|
|
|
@@ -40,7 +40,7 @@ The card shows the active subscription. `plan.name` and `plan.price` reach throu
|
|
|
40
40
|
|
|
41
41
|
The two header buttons are named actions of the subscriptions view, each with its own kind of behaviour. The views of the billing schema declare every action this page uses:
|
|
42
42
|
|
|
43
|
-
```ts title="config/billing/
|
|
43
|
+
```ts title="config/billing/ui.ts"
|
|
44
44
|
import { view } from '@protobase/schema'
|
|
45
45
|
import type { billingProfiles, invoices, paymentMethods, plans, subscriptions } from './billing-config'
|
|
46
46
|
|
|
@@ -73,7 +73,7 @@ export const invoicesView = view<typeof invoices>('invoices')
|
|
|
73
73
|
.actions((a) => [a.action('download', { label: 'Download PDF' })])
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
-
`a.update('cancel', ...)` sets `status` after its `confirm` question. `a.link` opens its `href`, with `{plan}` filled in from the record:
|
|
76
|
+
`a.update('cancel', ...)` sets `status` after its `confirm` question. `a.link` opens its `href`, with `{plan}` filled in from the record: an `href` leaves the app (`https:`, `mailto:`), while a place in the app is a `to`, such as `{ kind: 'record', resource: 'plans', key: '{plan}' }`; a path in the app as an `href` is refused. Cancel the plan in the story and the card says there is no active plan, because its `filter` no longer matches.
|
|
77
77
|
|
|
78
78
|
## 2. Who we bill
|
|
79
79
|
|
|
@@ -260,7 +260,7 @@ export const billing = page(
|
|
|
260
260
|
|
|
261
261
|
Two things here are not built-in blocks.
|
|
262
262
|
|
|
263
|
-
`SeatHistory` is a **custom component**. `component('SeatHistory')` declares it for the layout, with its props typed, and the element stays data: `{ type: 'SeatHistory', props: { months: 6 }, custom: true }`. The React code lives in the app, exported under the same name from `protobase.ui.tsx` at the project root, which the admin
|
|
263
|
+
`SeatHistory` is a **custom component**. `component('SeatHistory')` declares it for the layout, with its props typed, and the element stays data: `{ type: 'SeatHistory', props: { months: 6 }, custom: true }`. The React code lives in the app, exported under the same name from `protobase.ui.tsx` at the project root, which `protobase build` builds into a [plugin](../reference/plugins.md) the admin app loads. Inside a RecordCard, `useLayoutRecord()` gives it the record.
|
|
264
264
|
|
|
265
265
|
"Download PDF" is a named action without built-in behaviour (`a.action('download', ...)`), so it runs the handler registered under its name, with the record, the API client and the router. The ERP example has one of each, its component in a file of its own:
|
|
266
266
|
|
|
@@ -281,7 +281,7 @@ const send = async ({ record, recordKey, etag, client }: ActionContext) => {
|
|
|
281
281
|
export default defineUi({ actions: { send } })
|
|
282
282
|
```
|
|
283
283
|
|
|
284
|
-
The rest is familiar: a
|
|
284
|
+
The rest is familiar: a `Table` of the latest invoices, with a link to all of them, spanning two of the three columns, a count of open invoices, and a `Link` inside the text of a card.
|
|
285
285
|
|
|
286
286
|
If the app has no component registered under a name, the page says so where the component would be, and an action without a handler is disabled:
|
|
287
287
|
|
|
@@ -26,7 +26,7 @@ export const bookRepair = page(
|
|
|
26
26
|
)
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
Its `roles` say who may book: they are the people who get the page, and so **New**.
|
|
29
|
+
Its `roles` say who may book: they are the people who get the page, and so **New**. Protobase finds pages among the exports of `config/index.ts`, so export it there: `export { bookRepair } from './pages/book-repair'`.
|
|
30
30
|
|
|
31
31
|
## 2. The component
|
|
32
32
|
|
|
@@ -94,7 +94,7 @@ export const repairsView = view<typeof repairs>('repairs')
|
|
|
94
94
|
|
|
95
95
|
## 4. Create through a function
|
|
96
96
|
|
|
97
|
-
With its own page, the shop can make the [API function](api-functions.md) `book-repair` the only way in: it checks the answers, plans the job and inserts the repair with `db`, which skips the access rules. The resource's API then refuses creates:
|
|
97
|
+
With its own page, the shop can make the [API function](api-functions.md) `book-repair`, the default export of `functions/book-repair.ts`, the only way in: it checks the answers, plans the job and inserts the repair with `db`, which skips the access rules. The resource's API then refuses creates:
|
|
98
98
|
|
|
99
99
|
```ts
|
|
100
100
|
// config/repairs/data.ts
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
# Deploy
|
|
4
4
|
|
|
5
|
-
Ship a project as one bundle folder and run it with the serve runtime.
|
|
5
|
+
Ship a project as one bundle folder and run it with the serve runtime, on a host of your own or on Protobase Cloud from a push to GitHub.
|
|
6
6
|
|
|
7
|
-
A project ships as one bundle folder; the host runs protobase around it.
|
|
7
|
+
A project ships as one bundle folder; the host runs protobase around it. An app on Protobase Cloud deploys from a push to its GitHub branch instead, which builds and serves the bundle for it (see [Protobase Cloud](#protobase-cloud)).
|
|
8
8
|
|
|
9
9
|
```sh
|
|
10
10
|
bun run --cwd tests/apps/erp protobase build # the bundle to ship: tests/apps/erp/dist/
|
|
@@ -28,7 +28,7 @@ dist/
|
|
|
28
28
|
plugins and the app's version
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
The host serves `public/` itself and sends only the manifest's `api` paths to the runtime (`/api` and the two OAuth discovery documents of [MCP clients](../reference/auth.md#oauth-for-mcp-clients), and `/.well-known/webauthn
|
|
31
|
+
The host serves `public/` itself and sends only the manifest's `api` paths to the runtime (`/api` and the two OAuth discovery documents of [MCP clients](../reference/auth.md#oauth-for-mcp-clients)), and `/.well-known/webauthn` for an app on [several origins](../reference/auth.md#several-origins), which the manifest does not list, so loading the UI never needs a running container. With the UI it sends `X-Frame-Options: DENY` and `Content-Security-Policy: frame-ancestors 'none'`, as `protobase serve` does, so no other site frames the app's pages. The runtime serves the API alone; `protobase serve dist` serves the whole folder the same way, to check a bundle locally. The host passes `DATABASE_URL`, `PORT` (default 8787) and optionally `PROTOBASE_DB_CONNECTIONS` (the connections the app may open, so its functions and jobs leave one to requests, see [`serve`](../reference/cli.md#serve)), `REQUEST_LOG`, `PROTOBASE_SMTP_URL` and `PROTOBASE_MAIL_FROM` (the mail server and sender for [password reset](../reference/auth.md#password-reset) and emailed sign-in codes) `PROTOBASE_APP_NAME` (the app's name in that mail, see [`name`](../reference/config/app.md#name)) `PROTOBASE_SIGN_IN_*` (a provider people with an account sign in with, the [platform sign-in provider](../reference/auth.md#platform-sign-in-provider)) `PROTOBASE_OPERATOR_*` (the provider its staff sign in with for [staff sign-in](../reference/auth.md#staff-sign-in)), `PROTOBASE_ORIGINS` and `PROTOBASE_PASSKEY_DOMAIN` (the app's [other origins](../reference/auth.md#several-origins) and its passkey domain) `PROTOBASE_CORS_ORIGINS` (the websites that may call its API, see [CORS](../reference/api.md#cors)), `PROTOBASE_TRUSTED_PROXIES` (the proxies in front of the runtime, whose `X-Forwarded-For` names the client the sign-in limits count, see [Client addresses](../reference/auth.md#client-addresses)) and `PROTOBASE_SENTRY_DSN` (the app's [error tracker](../reference/api.md#error-reporting)), `PROTOBASE_URL` and `PROTOBASE_SECRET` (the app's address and secret, unless its config sets [`url` and `secret`](../reference/config/app.md)), plus the project's own settings, which its config reads where it serves. The runtime and the config module are plain JavaScript for Bun: no install, no TypeScript, no writes. The runtime supplies protobase and the dependencies it runs on the server (`pg`, `postgres`, `kysely`, `better-auth`, ...), so the config module carries only the project's code and the other packages it uses. The manifest's `protobase` is the version the bundle was built with, the building CLI's in a [bundled project](../reference/versioning.md#bundled-and-locked-projects) and the installed one in a locked project, and the host serves the bundle on the runtime of that version (see [Versioning](../reference/versioning.md#bundles-and-runtimes)). The manifest format and the routing rules are in the CLI reference: [`build`](../reference/cli.md#build), [`build-serve`](../reference/cli.md#build-serve) and [`serve`](../reference/cli.md#serve).
|
|
32
32
|
|
|
33
33
|
## Migrations
|
|
34
34
|
|
|
@@ -41,10 +41,10 @@ Every release pushes two public images to GitHub's registry, for `linux/amd64` a
|
|
|
41
41
|
| Image | What it holds |
|
|
42
42
|
| --- | --- |
|
|
43
43
|
| `ghcr.io/prototeamhq/protobase:<version>` | the serve runtime, compiled with Bun into `/opt/protobase/protobase-serve`, which serves the API of the bundle mounted at `/app` (and, given the folder, its app too, see [a self-hosted image](#a-self-hosted-image)); the release's prebuilt admin app at `/opt/protobase/shell`, which a host may serve for the bundle's [shell paths](../reference/plugins.md#the-shell) instead of the bundle's copy; Bun for its healthcheck on `/health`, and the C++ runtime native add-ons link. It runs as `nonroot` (65532) and writes nothing, so it runs with a read-only root filesystem |
|
|
44
|
-
| `ghcr.io/prototeamhq/protobase-dev:<version>` | Bun and the presets at `/opt/protobase/presets/<name>` (`erp`, `real-estate`, `scratch`), with the dependencies they share installed in `/workspace` and Bun's cache in `/opt/bun-cache`. It has no Node: the presets' scripts and the `protobase` command run on Bun. It runs as `bun` (1000) |
|
|
44
|
+
| `ghcr.io/prototeamhq/protobase-dev:<version>` | Bun, the `protobase` command of that version installed globally (in `/opt/protobase/cli`, on `PATH`), and the presets at `/opt/protobase/presets/<name>` (`erp`, `real-estate`, `scratch`), with the dependencies they share installed in `/workspace` and Bun's cache in `/opt/bun-cache`. The global `protobase` builds a bundled project with nothing installed and hands a locked one over to the CLI it installed (see [Bundled and locked projects](../reference/versioning.md#bundled-and-locked-projects)). It has no Node: the presets' scripts and the `protobase` command run on Bun. It runs as `bun` (1000) |
|
|
45
45
|
|
|
46
46
|
```sh
|
|
47
|
-
docker run -v "$PWD/dist:/app:ro" -p 127.0.0.1:8787:8787 -e DATABASE_URL -e PROTOBASE_URL -e PROTOBASE_SECRET ghcr.io/prototeamhq/protobase:
|
|
47
|
+
docker run -v "$PWD/dist:/app:ro" -p 127.0.0.1:8787:8787 -e DATABASE_URL -e PROTOBASE_URL -e PROTOBASE_SECRET ghcr.io/prototeamhq/protobase:"$VERSION" # the version of the @protobase/cli that built dist/
|
|
48
48
|
```
|
|
49
49
|
|
|
50
50
|
In `protobase-dev`, copy a preset into `/workspace` and `bun install --frozen-lockfile` has nothing to do; installed anywhere else, it comes from the cache, without the network.
|
|
@@ -54,7 +54,7 @@ The Dockerfiles are `docker/protobase/Dockerfile` and `docker/protobase-dev/Dock
|
|
|
54
54
|
```sh
|
|
55
55
|
bun run images:context # dist/images/protobase and dist/images/protobase-dev
|
|
56
56
|
docker build -f docker/protobase/Dockerfile -t protobase dist/images/protobase
|
|
57
|
-
docker build -f docker/protobase-dev/Dockerfile -t protobase-dev dist/images/protobase-dev
|
|
57
|
+
docker build -f docker/protobase-dev/Dockerfile --build-arg PROTOBASE_VERSION="$(bun -p "require('./package.json').version")" -t protobase-dev dist/images/protobase-dev
|
|
58
58
|
```
|
|
59
59
|
|
|
60
60
|
## A self-hosted image
|
|
@@ -62,8 +62,9 @@ docker build -f docker/protobase-dev/Dockerfile -t protobase-dev dist/images/pro
|
|
|
62
62
|
A product built on Protobase ships to self-hosters as one image: the runtime image with the bundle inside. Build the bundle with `protobase build --bun`, then:
|
|
63
63
|
|
|
64
64
|
```dockerfile
|
|
65
|
-
# The runtime of the @protobase/cli version that built dist
|
|
66
|
-
|
|
65
|
+
# The runtime of the @protobase/cli version that built dist/: docker build --build-arg VERSION=<that version> .
|
|
66
|
+
ARG VERSION
|
|
67
|
+
FROM ghcr.io/prototeamhq/protobase:${VERSION}
|
|
67
68
|
COPY dist /app
|
|
68
69
|
CMD ["/app"]
|
|
69
70
|
```
|
|
@@ -189,3 +190,18 @@ docker compose up -d
|
|
|
189
190
|
Stop any `protobase worker` processes before `migrate` too.
|
|
190
191
|
|
|
191
192
|
When a migration fails, `migrate` exits with an error and its transaction is rolled back, so the schema is unchanged. Set `APP_VERSION` back and `docker compose start app` brings the old version back on it. A plain `docker compose up -d` with the new version also stops the old one before `migrate`, but after a failure nothing serves until `APP_VERSION` is set back and `up -d` runs again. Going back after a migration that succeeded needs the backup.
|
|
193
|
+
|
|
194
|
+
## Protobase Cloud
|
|
195
|
+
|
|
196
|
+
An app on Protobase Cloud whose code is on GitHub follows one branch of its repository, the default branch unless the app was linked to another. A push to that branch deploys it; nothing else does, and a change on another branch, a tag or a pull request deploys nothing.
|
|
197
|
+
|
|
198
|
+
1. Protobase Cloud builds the branch's newest commit. While a build runs, later pushes wait, and the next build takes the newest commit then, so quick pushes give one build.
|
|
199
|
+
2. The build installs the packages with `bun install --frozen-lockfile` and runs `protobase build`. It runs neither the project's typecheck nor its tests.
|
|
200
|
+
3. The deploy stops the app's writes, then runs the project's `db:migrate`, the auth schema's migration and `protobase doctor --env DATABASE_URL` in one database transaction, which commits only when all of them pass. Pages keep reading meanwhile; a write, sign-in included, answers that the app is being updated.
|
|
201
|
+
4. Writes come back, the new version starts on its own and must answer `/health` with its startup checks, and only then does the app switch to it.
|
|
202
|
+
|
|
203
|
+
When a step fails, the previous version keeps serving on the database as it was, except after a failed start, which comes after the migrations committed: they stay applied. Each build reports on GitHub as the check run `Protobase deploy` on the commit it built, with the step that failed and the end of its output. A commit whose build failed is not built again: the fix is a new push.
|
|
204
|
+
|
|
205
|
+
Since the deploy runs neither the typecheck nor the tests, and refuses what `doctor` refuses, check a change before pushing it: the project's typecheck and tests, `protobase doctor --env DATABASE_URL` on a database with the migrations applied, and `protobase build`. The migrations run in one transaction, so a statement Postgres refuses in one, such as `create index concurrently`, fails the deploy. Protobase Cloud also pushes to the branch itself, for an update of the app's Protobase packages, so pull before pushing.
|
|
206
|
+
|
|
207
|
+
[`protobase skill install`](../reference/cli.md#skill) writes the `protobase-cloud` agent skill into the project, with how to check that a change went live and why a deploy failed, step by step.
|
|
@@ -77,7 +77,7 @@ import { StepsDisplay, StepsEditor } from './components/order-steps'
|
|
|
77
77
|
export { OrdersPerDay } from './components/orders-per-day'
|
|
78
78
|
|
|
79
79
|
export default definePlugin({
|
|
80
|
-
|
|
80
|
+
// ...the plugin's other entries, such as its actions
|
|
81
81
|
fields: { steps: { of: ['enum'], display: StepsDisplay, editor: StepsEditor } },
|
|
82
82
|
})
|
|
83
83
|
```
|
|
@@ -143,7 +143,7 @@ export const salesOverview = page(
|
|
|
143
143
|
)
|
|
144
144
|
```
|
|
145
145
|
|
|
146
|
-
`{ plugin: 'sales-tools' }` tells `protobase build` that the project's own `protobase.ui.tsx` does not have the component, so it does not fail on it. Start the app with `bun run protobase dev` and sign in: the start page shows the card with the five newest drafts, and `sales-tools 1.0.0` under them. `/api/meta` named the plugin, the app read its `plugin.json`, saw that it fits, and loaded its module and stylesheet.
|
|
146
|
+
`{ plugin: 'sales-tools' }` tells `protobase build` that the project's own `protobase.ui.tsx` does not have the component, so it does not fail on it. The ERP exports the page from `config/index.ts` already (`export { salesOverview } from './overview/page'`); in another app, add that export, since Protobase finds pages there. Start the app with `bun run protobase dev` and sign in: the start page shows the card with the five newest drafts, and `sales-tools 1.0.0` under them. `/api/meta` named the plugin, the app read its `plugin.json`, saw that it fits, and loaded its module and stylesheet.
|
|
147
147
|
|
|
148
148
|
## 6. Change the plugin, not the app
|
|
149
149
|
|
|
@@ -8,7 +8,7 @@ Until 0.12, `protobase build` built the whole admin app into each bundle, with t
|
|
|
8
8
|
|
|
9
9
|
## 1. Update and rebuild
|
|
10
10
|
|
|
11
|
-
Move the project's `@protobase` packages to 0.12
|
|
11
|
+
Move the project's `@protobase` packages to 0.12, as for any release, and build; `^0.12` takes 0.12's patches only, since below 1.0 a new minor is a release of its own, moved to the same way once the project builds on 0.12:
|
|
12
12
|
|
|
13
13
|
```sh
|
|
14
14
|
bun add @protobase/cli@^0.12 @protobase/server@^0.12 @protobase/schema@^0.12 @protobase/layout@^0.12 @protobase/ui@^0.12
|
|
@@ -53,7 +53,7 @@ export const ticketNotes = resource('ticket_notes')
|
|
|
53
53
|
.access({ delete: deskOnly })
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
-
Only the desk's own admins delete: the [access rule](../reference/access.md) holds for everyone who reaches the desk's API, the shop's people included.
|
|
56
|
+
The tables come first, as a migration of the desk's (a new file in `db/migrations/`, applied with `bun run db:migrate`), and the resources are exported from the desk's `config/index.ts`, where Protobase finds them: `export * from './tickets/data'`. Only the desk's own admins delete: the [access rule](../reference/access.md) holds for everyone who reaches the desk's API, the shop's people included.
|
|
57
57
|
|
|
58
58
|
```ts
|
|
59
59
|
// desk: config/tickets/ui.ts
|
|
@@ -12,7 +12,7 @@ This guide follows that admin from nothing to something the front desk and the w
|
|
|
12
12
|
|
|
13
13
|
Everything starts with the data config: what the tables are, as they are. `protobase scaffold` writes it from the database, and Pip tidies it up:
|
|
14
14
|
|
|
15
|
-
```ts title="config/data.ts"
|
|
15
|
+
```ts title="config/bike-shop/data.ts"
|
|
16
16
|
import { f, resource } from '@protobase/schema'
|
|
17
17
|
|
|
18
18
|
// Pip's bike shop: customers bring bikes in, the workshop repairs them. Two tables of a Postgres database the
|
|
@@ -56,11 +56,11 @@ export const repairs = resource('repairs')
|
|
|
56
56
|
.validate((repair) => (repair.status === 'collected' && !repair.paid ? [{ field: 'paid', message: 'A bike leaves the shop paid' }] : undefined))
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
-
The fields follow the columns, with what the database does not say added: which fields can be filtered and sorted, which ones the database fills in (`dbDefault`), which are read-only. `notes` lives in a column called `internal_notes`, and `legacy_ref: null` keeps an old column out for good. The `validate` rule holds the shop's one firm rule: a bike does not leave unpaid.
|
|
59
|
+
`scaffold` writes a file per table, `config/repairs/data.ts` and `config/customers/data.ts`, and exports each from `config/index.ts`, where Protobase finds the resources; Pip keeps both in one file, exported the same way: `export * from './bike-shop/data'`. The fields follow the columns, with what the database does not say added: which fields can be filtered and sorted, which ones the database fills in (`dbDefault`), which are read-only. `notes` lives in a column called `internal_notes`, and `legacy_ref: null` keeps an old column out for good. The `validate` rule holds the shop's one firm rule: a bike does not leave unpaid.
|
|
60
60
|
|
|
61
|
-
For the admin to list repairs, a view is enough, even an empty one:
|
|
61
|
+
For the admin to list repairs, a view is enough, even an empty one. A `ui.ts` in a folder of `config/` is found by its path, without an export:
|
|
62
62
|
|
|
63
|
-
```ts title="config/ui.ts"
|
|
63
|
+
```ts title="config/bike-shop/ui.ts"
|
|
64
64
|
import { view } from '@protobase/schema'
|
|
65
65
|
import type { customers, repairs } from './data'
|
|
66
66
|
|
|
@@ -77,7 +77,7 @@ That is already a working admin: every column, sorting, paging, a record page an
|
|
|
77
77
|
|
|
78
78
|
The list shows everything, including the problem descriptions nobody reads in a list. The front desk wants the repair number, whose bike, what state it is in, and who is on it, newest first.
|
|
79
79
|
|
|
80
|
-
```ts title="config/ui.ts"
|
|
80
|
+
```ts title="config/bike-shop/ui.ts"
|
|
81
81
|
import { view } from '@protobase/schema'
|
|
82
82
|
import type { customers, repairs } from './data'
|
|
83
83
|
|
|
@@ -111,7 +111,7 @@ export const repairsView = view<typeof repairs>('repairs')
|
|
|
111
111
|
|
|
112
112
|
On Saturdays the desk asks the same questions over and over: what is ready, what is Sem working on, what came in this week, what is not paid. Filters answer them in one click.
|
|
113
113
|
|
|
114
|
-
```ts title="config/ui.ts"
|
|
114
|
+
```ts title="config/bike-shop/ui.ts"
|
|
115
115
|
import { customersView, repairsView as named } from './step-2'
|
|
116
116
|
|
|
117
117
|
// Step 3: the filters the front desk reaches for, and a chart of bookings above the list.
|
|
@@ -135,7 +135,7 @@ From here on each step starts from the view of the step before (`named` is step
|
|
|
135
135
|
|
|
136
136
|
The record page still lists every field in one long column. The paper card the desk uses has three parts: the bike and its problem, the workshop's side, and the money. The layout copies it.
|
|
137
137
|
|
|
138
|
-
```ts title="config/ui.ts"
|
|
138
|
+
```ts title="config/bike-shop/ui.ts"
|
|
139
139
|
import { l } from '@protobase/schema'
|
|
140
140
|
import { customersView, repairsView as filtered } from './step-3'
|
|
141
141
|
|
|
@@ -170,7 +170,7 @@ l.related('Parts used', { resource: 'repair_parts', field: 'repair_id', when: 'e
|
|
|
170
170
|
|
|
171
171
|
Two things happen to every repair: it becomes ready, and it gets collected (and paid). Typing a status into a dropdown is how mistakes happen, so they become buttons. And the mechanics would rather not see prices at all.
|
|
172
172
|
|
|
173
|
-
```ts title="config/ui.ts"
|
|
173
|
+
```ts title="config/bike-shop/ui.ts"
|
|
174
174
|
import { l } from '@protobase/schema'
|
|
175
175
|
import { customersView, repairsView as laidOut } from './step-4'
|
|
176
176
|
|
|
@@ -80,7 +80,7 @@ The action runs at `POST /api/v1/{resource}/{key}:generate` with `{ "action": "<
|
|
|
80
80
|
| `404` | `not-found` | The caller's view has no AI action of that name, or there is no such record. |
|
|
81
81
|
| `403` | `ai-forbidden` | The caller may not read a field the prompt reads, or update the field it writes. |
|
|
82
82
|
| `422` | `ai-no-value` | Every field the prompt reads is empty, or the model answered nothing. |
|
|
83
|
-
| `502` | `ai-unavailable` | The model failed or took more than 60 seconds. The user sees only that; the endpoint's message goes to the app's error reporting (`
|
|
83
|
+
| `502` | `ai-unavailable` | The model failed or took more than 60 seconds. The user sees only that; the endpoint's message goes to the app's error reporting (its [`hooks/error.ts`](config/api.md#code-of-the-api)). |
|
|
84
84
|
| `503` | `ai-not-configured` | No model is set; startup normally catches this first. |
|
|
85
85
|
|
|
86
86
|
Every check is made before the model is asked.
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
The REST API that @protobase/server generates, with its routes, access, filters, writes, batches and errors.
|
|
6
6
|
|
|
7
|
-
`@protobase/server` turns resource definitions into a Hono app that follows Google's API design conventions ([AIP-131 to 136](https://google.aip.dev/131), [158](https://google.aip.dev/158), [160](https://google.aip.dev/160)). It uses Web APIs only and runs on Node and Workers;
|
|
7
|
+
`@protobase/server` turns resource definitions into a Hono app that follows Google's API design conventions ([AIP-131 to 136](https://google.aip.dev/131), [158](https://google.aip.dev/158), [160](https://google.aip.dev/160)). It uses Web APIs only and runs on Node, Bun and Workers; `protobase dev` and `serve` serve it on Node or Bun.
|
|
8
8
|
|
|
9
9
|
`protobase dev` and `serve` build it from the project: the resources of `config/`, the functions of `functions/`, sign-in from `auth`, and the API's settings from the top-level keys of [`protobase.config.ts`](config.md), such as `statementTimeoutMs` and `scanGuard`. In code of its own, an app builds it with `createAdmin`, whose `options` take the same settings:
|
|
10
10
|
|
|
@@ -23,7 +23,7 @@ const admin = createAdmin({
|
|
|
23
23
|
})
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
Run the ERP example with `bun run --cwd tests/apps/erp serve` (port 8787, Better Auth login, organization
|
|
26
|
+
Run the ERP example with `bun run --cwd tests/apps/erp serve` (port 8787, Better Auth login, the user's active [organization](auth.md#organizations) as tenant; `REQUEST_LOG=true` logs requests). Interactive reference: `/api/docs`; like `/api/openapi.json` it needs a bearer token, because the document lists what the caller may see and do. Every route answers `401` without a valid token; get one with `protobase token you@example.com`. A project whose roles define [`anonymous`](access.md#anonymous-access) serves the resources API to requests without a token as that role.
|
|
27
27
|
|
|
28
28
|
## Routes
|
|
29
29
|
|
|
@@ -196,7 +196,7 @@ The API sends no CORS headers until it has something to allow: other websites in
|
|
|
196
196
|
|
|
197
197
|
## Safety
|
|
198
198
|
|
|
199
|
-
- Every request runs in a transaction with `SET LOCAL statement_timeout` (`statementTimeoutMs`, default 1 s), so a slow query fails where it runs instead of holding a connection that other requests wait for. List, search, get, histogram, series, map and seek transactions are read-only. A query that runs longer is stopped: a `504` `statement-timeout` that names the request, its limit and the ways out, such as `GET /api/v1/orders ran a query longer than 1 s, so the database stopped it. Make the query faster, such as with an index or a narrower filter, or move the work into a function or job with longQueries: true, whose queries may run up to 30 s.` It goes to `options.onUnhandledError` and the [error tracker](#error-reporting) like a `500`. A read that needs longer has no way to opt out: give it an index, or move it into a [function](../guides/api-functions.md#long-queries) or [job](jobs.md) with `longQueries`.
|
|
199
|
+
- Every request runs in a transaction with `SET LOCAL statement_timeout` (`statementTimeoutMs`, default 1 s), so a slow query fails where it runs instead of holding a connection that other requests wait for. List, search, get, histogram, series, map and seek transactions are read-only. A query that runs longer is stopped: a `504` `statement-timeout` that names the request, its limit and the ways out, such as `GET /api/v1/orders ran a query longer than 1 s, so the database stopped it. Make the query faster, such as with an index or a narrower filter, or move the work into a function or job with longQueries: true, whose queries may run up to 30 s.` It goes to the app's error hook (`hooks/error.ts`, `createAdmin`'s `options.onUnhandledError`) and the [error tracker](#error-reporting) like a `500`. A read that needs longer has no way to opt out: give it an index, or move it into a [function](../guides/api-functions.md#long-queries) or [job](jobs.md) with `longQueries`.
|
|
200
200
|
- Under `protobase dev` and `serve`, a request waits at most 2 seconds for a free database connection. When every connection stays busy that long, it is a `503` `connections-busy` with `Retry-After: 1` that names the request, reported the same way, rather than a request that hangs behind slow ones.
|
|
201
201
|
- **Scan guard**: a list, `:search`, `:seek`, `:map` page, card photos, `:facets` and `:aggregate` read only columns an index serves, so they stay cheap however many rows match. The server reads each table's valid indexes from the catalog once, then checks every column the caller's filter, the role's row filter, the sort's first field and a facet's or an aggregate's grouped field read:
|
|
202
202
|
- Comparisons, `in`, null checks, sorts and facets need a btree index with the column as a key, every key before it pinned by the query: by `=` or `in` in the filter (outside `OR` and `NOT`), by the tenant or by soft delete. `(for_sale, status, published_at desc)` serves `for_sale = true AND status = "available"` sorted by `published_at desc`, but not `status` alone. `=` on text may use a pg_trgm index instead.
|
|
@@ -207,7 +207,7 @@ The API sends no CORS headers until it has something to allow: other websites in
|
|
|
207
207
|
|
|
208
208
|
## Errors
|
|
209
209
|
|
|
210
|
-
Every error is `application/problem+json` (RFC 9457) with `type` (`urn:protobase:problem:<slug>`), `title`, `status`, `detail`, `instance`. Filter and `order_by` errors add `parameter` and `errors: [{ code, message, hint, span: { start, end } }]`; invalid parameters add `errors: [{ parameter, message }]`. A create or update whose body fails the checks is `invalid-record` with `errors: [{ field, code, message, params }]`, `code` one of `required`, `invalid-value`, `read-only`, `unknown-field` and `invalid-record` (a `.validate()` rule); `params` is the limit an invalid value broke, such as `{ min }`, `{ max }` or a decimal's `{ precision, scale }`. Database constraint failures map to `409` or `400` without the raw message. A create or update that writes the position of a resource with `after` so a record ranks at or above one it depends on is a `409` `ranks-above-dependency`, as in a [`reorder`](#batch-writes). A delete that other records still point at is a `409` `conflict` with `blockedBy: { resource, field? }`: their resource, when the caller may list it, and its relation field pointing at the record, when they may filter by it, so a client can open those records; the admin app's toast names them, such as "Orders still point at this company.", with a link to that list. Postgres names one table of them only, so `blockedBy` holds one resource; anything unexpected is a `500` with a fixed detail, reported to `options.onUnhandledError` and, when it is set, the [error tracker](#error-reporting).
|
|
210
|
+
Every error is `application/problem+json` (RFC 9457) with `type` (`urn:protobase:problem:<slug>`), `title`, `status`, `detail`, `instance`. Filter and `order_by` errors add `parameter` and `errors: [{ code, message, hint, span: { start, end } }]`; invalid parameters add `errors: [{ parameter, message }]`. A create or update whose body fails the checks is `invalid-record` with `errors: [{ field, code, message, params }]`, `code` one of `required`, `invalid-value`, `read-only`, `unknown-field` and `invalid-record` (a `.validate()` rule); `params` is the limit an invalid value broke, such as `{ min }`, `{ max }` or a decimal's `{ precision, scale }`. Database constraint failures map to `409` or `400` without the raw message. A create or update that writes the position of a resource with `after` so a record ranks at or above one it depends on is a `409` `ranks-above-dependency`, as in a [`reorder`](#batch-writes). A delete that other records still point at is a `409` `conflict` with `blockedBy: { resource, field? }`: their resource, when the caller may list it, and its relation field pointing at the record, when they may filter by it, so a client can open those records; the admin app's toast names them, such as "Orders still point at this company.", with a link to that list. Postgres names one table of them only, so `blockedBy` holds one resource; anything unexpected is a `500` with a fixed detail, reported to the app's error hook (`hooks/error.ts`, `createAdmin`'s `options.onUnhandledError`) and, when it is set, the [error tracker](#error-reporting).
|
|
211
211
|
|
|
212
212
|
| Status | Slugs |
|
|
213
213
|
| --- | --- |
|
|
@@ -10,26 +10,31 @@ A Bun workspace of npm packages under the `@protobase` scope, in `packages/<name
|
|
|
10
10
|
|
|
11
11
|
| Package | Folder | Entry points | Runs in | Depends on |
|
|
12
12
|
| --- | --- | --- | --- | --- |
|
|
13
|
-
| `@protobase/schema` | `packages/schema` | `@protobase/schema` | anywhere | no other `@protobase` package |
|
|
13
|
+
| `@protobase/schema` | `packages/schema` | `@protobase/schema`, `@protobase/schema/png-icons`; `@protobase/schema/internal` for the other packages only | anywhere | no other `@protobase` package |
|
|
14
14
|
| `@protobase/layout` | `packages/layout` | `@protobase/layout`, `@protobase/layout/jsx-runtime`, `@protobase/layout/jsx-dev-runtime` | anywhere | `schema` |
|
|
15
15
|
| `@protobase/query` | `packages/query` | `@protobase/query` | server | `schema` |
|
|
16
16
|
| `@protobase/client` | `packages/client` | `@protobase/client` | anywhere with `fetch` | `schema`, `layout` |
|
|
17
|
-
| `@protobase/ui` | `packages/ui` | `@protobase/ui`; the admin app in `src/app` | browser | `schema`, `layout`, `client` |
|
|
18
|
-
| `@protobase/server` | `packages/server` | `@protobase/server` | server | `schema`, `layout`, `query` |
|
|
19
|
-
| `@protobase/
|
|
17
|
+
| `@protobase/ui` | `packages/ui` | `@protobase/ui`, `@protobase/ui/theme.css`, `@protobase/ui/styles.css`; the admin app in `src/app` | browser | `schema`, `layout`, `client` |
|
|
18
|
+
| `@protobase/server` | `packages/server` | `@protobase/server`, `@protobase/server/auth-store`, `@protobase/server/config-exports`, `@protobase/server/email`, `@protobase/server/vapid`; `@protobase/server/internal` for the other packages only | server | `schema`, `layout`, `query` |
|
|
19
|
+
| `@protobase/config` | `packages/config` | `@protobase/config`, `@protobase/config/schema.json` | anywhere | types of `server` only: it runs nothing besides `defineConfig` |
|
|
20
|
+
| `@protobase/cli` | `packages/cli` | the `protobase` command (`bin/protobase.mjs`), `@protobase/cli/auth`, `@protobase/cli/runner` | Node and Bun | `config`, `schema`, `layout`, `query`, `server`, `ui` |
|
|
21
|
+
| `@protobase/mobile` | `packages/mobile` | none: the Capacitor packages and native plugins `protobase mobile` installs on first use | the app's iOS and Android projects | none |
|
|
22
|
+
| `create-protobase` | `packages/create-protobase` | the `create-protobase` command, for `npm create protobase` | Node | none |
|
|
20
23
|
| `@protobase/presets` | `packages/presets` | none: private, `bun run presets:write` writes a project per preset | Bun | none; each preset depends on the `@protobase` packages of the major it is written at, locked at that version |
|
|
21
24
|
| `tests/apps/*` | | none | any | `@protobase/*` entry points only |
|
|
22
25
|
|
|
23
|
-
The presets are written from `tests/apps/erp`, `tests/apps/real-estate` and `tests/apps/scratch` (from scratch) by `bun run presets:write <version> <dir>`, run from a clone of this repository; `npm create protobase` (`packages/create-protobase`) writes them too, without a lockfile. Each is a standalone copy with the `@protobase` packages in the caret range of `<version>`, `^x.y.z`, so an app takes the updates semver calls compatible: within that major from 1.0 on, and within that minor below 1.0, where a minor may break, and its own `bun.lock` at exactly `<version>`. The three declare the same dependencies, so one `node_modules` fits them all, and their `db:migrate` (the auth schema's migrations included), `typecheck` and `test` scripts take their settings from the environment, or a `.env` beside them, and reach nothing outside the project.
|
|
26
|
+
The presets are written from `tests/apps/erp`, `tests/apps/real-estate` and `tests/apps/scratch` (from scratch) by `bun run presets:write <version> <dir>`, run from a clone of this repository; `npm create protobase` (`packages/create-protobase`) writes them too, without a lockfile. Each is a standalone copy with the `@protobase` packages in `devDependencies`, so an app made from it is [bundled](versioning.md#bundles-and-runtimes) and runs on the CLI's own copies, in the caret range of `<version>`, `^x.y.z`, so an app takes the updates semver calls compatible: within that major from 1.0 on, and within that minor below 1.0, where a minor may break, and its own `bun.lock` at exactly `<version>`. Its `tsconfig.json` extends `.protobase/tsconfig.json`, which [`protobase types`](cli.md#types) writes, as `dev`, `build` and its `typecheck` and `test` scripts do first, and its database scripts run with [`protobase run`](cli.md#run). The examples in this repository list the packages in `dependencies`, locked to the workspace's, and their `tsconfig.json` extends nothing: Vite reads it when it transforms their files, and would fail before the file it extends is written. The three declare the same dependencies, so one `node_modules` fits them all, and their `db:migrate` (the auth schema's migrations included), `typecheck` and `test` scripts take their settings from the environment, or a `.env` beside them, and reach nothing outside the project.
|
|
24
27
|
|
|
25
28
|
The JSX runtime belongs to `@protobase/layout` because a layout file names one package in `@jsxImportSource @protobase/layout`, and TypeScript and Vite look up `jsx-runtime` and `jsx-dev-runtime` under it. Each field type is split along the same lines: its Zod builder is `packages/schema/src/fields/<type>.ts` and its SQL parameter conversion `packages/query/src/fields/<type>.ts`.
|
|
26
29
|
|
|
27
30
|
Every package lists the packages it imports in its `package.json` (`workspace:*` for its `@protobase` dependencies), so it installs and works on its own. Rules, enforced by `bun run check:boundaries` (`.dependency-cruiser.cjs`):
|
|
28
31
|
|
|
29
32
|
- A package imports only the `@protobase` packages in the table above, so `@protobase/ui` never reaches `query`, `server` or `cli`, and `@protobase/layout` only `schema`: layouts are built in the config, checked on the server and rendered in the browser.
|
|
33
|
+
- `@protobase/config` imports types only, so reading a config loads nothing but it and the config.
|
|
30
34
|
- A package imports another by its name and entry point, never by a path into its source.
|
|
31
35
|
- A package's code (not its tests and stories) imports only what its `package.json` lists in `dependencies`.
|
|
32
36
|
- Examples, their tests and `test-support/` import the packages by name, never by path.
|
|
37
|
+
- Only an encrypted field's reveal and the `encryption` commands decrypt its values.
|
|
33
38
|
- No circular dependencies.
|
|
34
39
|
|
|
35
40
|
In this repository, entry points export TypeScript source directly and the CLI runs its source on Bun, or on Node through [tsx](https://tsx.is), so nothing needs a build. The published packages are built to JavaScript in `dist` by `bun run build` and `bun pm pack` (`scripts/publish.mjs`) (see [CLI](cli.md#how-it-runs)). The other builds are for deployment: the serve runtime, `packages/cli/src/serve/main.ts` bundled with its dependencies into `dist/protobase-serve.js` by `protobase build-serve`, the shell, a production build of the admin app (`packages/ui/src/app`) shipped in `@protobase/ui`'s `dist/shell` and the protobase image, and a project's bundle, its config module plus a copy of the shell and the project's `protobase.ui.tsx` built as a [plugin](plugins.md), by `protobase build` (see [CLI](cli.md#build)).
|
|
@@ -58,6 +63,6 @@ Filters are Google AIP-160 text. Parsing, printing, `order_by` and the generic c
|
|
|
58
63
|
|
|
59
64
|
## Documentation
|
|
60
65
|
|
|
61
|
-
`website/` is this site. `bun run docs:dev` serves it on port 4321; `bun run docs:build` writes `website/dist/` and fails on a broken internal link or anchor, so CI runs it on every pull request, followed by `bun run docs:check`, which opens every page in Chromium and fails on a console error or a failed request. Pages are Markdown or MDX in `website/src/content/docs/`, and the sidebar is listed in `website/
|
|
66
|
+
`website/` is this site. `bun run docs:dev` serves it on port 4321; `bun run docs:build` writes `website/dist/` and fails on a broken internal link or anchor, so CI runs it on every pull request, followed by `bun run docs:check`, which opens every page in Chromium and fails on a console error or a failed request. Pages are Markdown or MDX in `website/src/content/docs/`, and the sidebar is listed in `website/sidebar.mjs`.
|
|
62
67
|
|
|
63
68
|
Every push to `main` builds the site and deploys it, and so does running the workflow by hand (`gh workflow run docs.yml`); either way it deploys to the Cloudflare Pages project `protobase-docs`, served at `docs.protobase.net` (`.github/workflows/docs.yml`). The workflow reads the Cloudflare account id from the repository variable `CLOUDFLARE_ACCOUNT_ID` and a token with Cloudflare Pages edit permission from the repository secret `CLOUDFLARE_API_TOKEN`.
|
|
@@ -68,7 +68,7 @@ Making the query role needs `CREATEROLE` once, for the role that applies the mig
|
|
|
68
68
|
|
|
69
69
|
`assistant/tools.ts` adds tools of the app's own, which the built-in backend offers after its two: its default export is an array of tools, found by that path when the app starts. A tool is `defineTool({ name, description, parameters, run })` from `@protobase/server`: `parameters` is the JSON Schema of its arguments, and `run(args, context)` returns the text the model reads. A name must be 1 to 64 letters, digits, `_` or `-`, and a name taken twice stops the server at startup. A backend elsewhere has its own tools, so the file does nothing there, nor with `assistant: false`. A tool's `annotations` are MCP's tool hints (`readOnlyHint`, `destructiveHint`, ...), which the dock ignores; the same tools can be offered over the app's [MCP endpoint](mcp.md#building-on-it).
|
|
70
70
|
|
|
71
|
-
`context` holds the user's `session`, `show(part)` to add a part to the answer, `approve(request)` for an approval card, `conversation` (the dock's, absent over MCP), `resources()` (the resources the user may read, restricted to their fields, with their views), and `records`: `list(resource, params)` with the REST API's list parameters, `get(resource, key)`, `create(resource, data)`, `update(resource, key, data, { etag? })` (without an ETag it updates any version), `delete(resource, key, { etag? })` (soft on a resource with `.softDelete()`) and `softDeleteField(resource)` (the field a delete sets, or `undefined` when a delete removes the record) on the app's resources **as the user**, through their access rules, tenant scope, validation and write hooks, as in the REST API.
|
|
71
|
+
`context` holds the user's `session`, `show(part)` to add a part to the answer, `approve(request)` for an approval card, `conversation` (the dock's, absent over MCP), `resources()` (the resources the user may read, restricted to their fields, with their views), and `records`: `list(resource, params)` with the REST API's list parameters, `get(resource, key)`, `create(resource, data)`, `update(resource, key, data, { etag? })` (without an ETag it updates any version), `delete(resource, key, { etag? })` (soft on a resource with `.softDelete()`) and `softDeleteField(resource)` (the field a delete sets, or `undefined` when a delete removes the record) on the app's resources **as the user**, through their access rules, tenant scope, validation and write hooks, as in the REST API. `get`, `create`, `update` and `delete` each answer `{ record, etag }`, and `list` a page of records. `batch(operations)` runs the operations of a REST [batch write](api.md#batch-writes) in one transaction and answers its `results`; a refusal or a missing record rejects with an `HttpProblem`, whose `detail` a tool can return to the model as text.
|
|
72
72
|
|
|
73
73
|
A tool with a [widget](#widget-parts) creates or finds what it is about, shows a widget with its id, and returns the id and the state at that moment:
|
|
74
74
|
|