@protobase/cli 0.46.10 → 0.46.12

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.
Files changed (74) hide show
  1. package/dist/auth/register.js +1 -2
  2. package/dist/auth/write-migration.js +1 -1
  3. package/dist/build/app-icons.js +1 -1
  4. package/dist/build/config-bundle.js +1 -1
  5. package/dist/build/deploy-bundle.js +2 -2
  6. package/dist/build/entry-code.js +1 -1
  7. package/dist/build/plugin-build.js +3 -3
  8. package/dist/build/plugin-fields.js +1 -1
  9. package/dist/build/service-worker-code.js +1 -1
  10. package/dist/build/shell.js +2 -2
  11. package/dist/build/ui-check.js +2 -2
  12. package/dist/build/vite-bundle.js +1 -1
  13. package/dist/bundle/manifest.js +1 -1
  14. package/dist/cli/package.js +1 -1
  15. package/dist/db/connect.js +8 -5
  16. package/dist/dev/check-database.js +5 -3
  17. package/dist/dev/entry.d.ts +2 -0
  18. package/dist/dev/entry.js +6 -10
  19. package/dist/dev/login-line.js +21 -0
  20. package/dist/dev/loopback.js +42 -0
  21. package/dist/dev/project.js +2 -2
  22. package/dist/dev/run.js +19 -11
  23. package/dist/dev/startup-logger.js +24 -0
  24. package/dist/doctor/run.js +4 -1
  25. package/dist/encryption/register.js +1 -2
  26. package/dist/error-message.js +15 -0
  27. package/dist/files/register.js +1 -2
  28. package/dist/infer/proposal.js +1 -1
  29. package/dist/main.js +34 -26
  30. package/dist/migration/load-project.js +1 -1
  31. package/dist/migration/register.js +7 -4
  32. package/dist/migration/summary.js +15 -0
  33. package/dist/mobile/local-spec.js +1 -1
  34. package/dist/mobile/run.js +1 -1
  35. package/dist/mobile/web-part.js +2 -2
  36. package/dist/mobile/workspace.js +1 -1
  37. package/dist/notifications/register.js +1 -2
  38. package/dist/organizations/api.js +15 -0
  39. package/dist/organizations/register.js +5 -15
  40. package/dist/project/favicon-link.js +1 -1
  41. package/dist/project/load-bundle-project.js +2 -2
  42. package/dist/project/load-data-config.js +2 -2
  43. package/dist/project/placeholder-secret.js +9 -0
  44. package/dist/scaffold/existing-config.js +4 -1
  45. package/dist/scaffold/plan.js +17 -5
  46. package/dist/scaffold/project.js +2 -1
  47. package/dist/scaffold/prompt.js +12 -5
  48. package/dist/scaffold/protobase-tables.js +44 -0
  49. package/dist/scaffold/run.js +3 -1
  50. package/dist/scaffold/ui-fields.js +3 -0
  51. package/dist/scaffold/ui-file.js +42 -5
  52. package/dist/serve/app.js +1 -1
  53. package/dist/serve/bundle-version.js +1 -1
  54. package/dist/serve/create-admin.js +3 -3
  55. package/dist/serve/host-modules.js +5 -5
  56. package/dist/serve/lifecycle.js +3 -3
  57. package/dist/serve/mobile-release.js +1 -1
  58. package/dist/serve/serve-bundle-path.js +1 -1
  59. package/dist/serve/serve-bundle.js +3 -3
  60. package/dist/serve/serve-dir.js +2 -2
  61. package/dist/supabase/dump-phase.js +2 -2
  62. package/dist/supabase/load-phase.js +2 -2
  63. package/dist/supabase/register.js +1 -1
  64. package/dist/supabase/storage-phase.js +1 -1
  65. package/dist/users/commands.js +7 -1
  66. package/dist/users/register.js +17 -11
  67. package/dist/users/users-api.js +2 -1
  68. package/dist/worker/start-worker.js +2 -2
  69. package/package.json +6 -6
  70. package/skills/protobase/SKILL.md +1 -0
  71. package/skills/protobase/references/getting-started.md +5 -1
  72. package/skills/protobase/references/guides/existing-database.md +112 -0
  73. package/skills/protobase/references/reference/auth.md +6 -6
  74. package/skills/protobase/references/reference/cli.md +19 -11
@@ -12,7 +12,7 @@ bun run protobase <command> # from the project, config folde
12
12
  bun run --cwd examples/erp protobase <command> # in this repository, for an example
13
13
  ```
14
14
 
15
- Any package manager installs the packages, and the command runs on Node or on Bun: `npm install` and `npx protobase <command>` work the same. The bin starts with `#!/usr/bin/env node`, so where Node is installed `bun run protobase` starts it on Node, unless the project's `bunfig.toml` sets `[run] bun = true`, as the presets' does.
15
+ Any package manager installs the packages, and the command runs on Node or on Bun: `npm install` and `npx protobase <command>` work the same. The bin starts with `#!/usr/bin/env node`, so where Node is installed `bun run protobase` starts it on Node, unless the project's `bunfig.toml` sets `[run] bun = true`, as the presets' does. `protobase --version` (or `-v`) prints the Protobase version.
16
16
 
17
17
  ## How it runs
18
18
 
@@ -27,21 +27,25 @@ The CLI reads the database with `default_transaction_read_only = on`, so it can
27
27
  ## `scaffold`
28
28
 
29
29
  ```sh
30
- protobase scaffold <connection string | --env DATABASE_URL> [target] [options]
30
+ protobase scaffold [connection string | --env VAR] [target] [options]
31
31
  ```
32
32
 
33
- `target` is `all` (default), `schema`, `schema.table` or `schema.table.column`. Tables are introspected from `pg_catalog`; `config/<resource>/data.ts` is created or extended.
33
+ Without a connection string or `--env`, the URL is `DATABASE_URL`, from the environment or the nearest `.env` at or above the current directory, as `dev` reads it. `target` is `all` (default), `schema`, `schema.table` or `schema.table.column`. Tables are introspected from `pg_catalog`; `config/<resource>/data.ts` is created or extended.
34
+
35
+ Protobase's own tables are left out, since they hold password hashes, OAuth tokens and signing keys: the `auth` schema, another schema holding Better Auth's `user`, `session`, `account` and `verification` tables (in `public`, only the auth store's tables), and pg-boss's `jobs` schema. A line names each one skipped; a target naming the schema scaffolds it anyway. A resource an earlier run made over one of them gets a warning to remove it.
34
36
 
35
37
  | Option | Effect |
36
38
  | --- | --- |
37
39
  | `--config <dir>` | config folder, default `config` |
38
40
  | `--yes` | accept every proposal, no prompts (required without a TTY) |
39
41
  | `--dry-run` | print a diff, write nothing |
40
- | `--ui` | also write `ui.ts` (`.names()` and `.list()`) |
42
+ | `--ui` | also write `ui.ts` (`.names()` and `.list()`); the list never shows a secret-like column (`password`, `hash`, `token`, `secret`, `salt`, `otp`, `private_key`, `api_key` in its name) |
41
43
  | `--ui-list`, `--ui-section <names\|list>` | write only those `ui.ts` sections |
42
44
  | `--exclude <schema[.table]>` | skip tables, repeatable |
43
45
 
44
- Interactively, each new column shows its proposal: accept, edit (name, type) or ignore (writes `field: null`; key columns cannot be ignored).
46
+ Interactively, each new column shows its proposal: accept, accept all (this one and every one after it, without asking), edit (name, type) or ignore (writes `field: null`; key columns cannot be ignored).
47
+
48
+ The list `--ui` writes shows five columns at most: the key unless it is a uuid, up to two relations, then the other fields but long text, json and audit timestamps. It sorts newest first by a sortable `created_at` (or `inserted_at`, `createdAt`, ...), else by another sortable date or timestamp, else not at all.
45
49
 
46
50
  ### Inference
47
51
 
@@ -56,10 +60,10 @@ Interactively, each new column shows its proposal: accept, edit (name, type) or
56
60
  | anything else (`ltree`, arrays, ...) | `f.text().readOnly()` |
57
61
 
58
62
  - `NOT NULL` absent: `.optional()`. Literal default: `.default(v)`.
59
- - Computed defaults (function, sequence, expression, `GENERATED BY DEFAULT` identity): `.dbDefault()`. It also gets `.readOnly()` when the column is an identity column, a primary-key column, or an audit timestamp (`created_at`, `inserted_at`, `updated_at`, `modified_at`); other computed defaults, such as `order_date DEFAULT current_date`, stay editable. `GENERATED ALWAYS` identity and generated columns are only `.readOnly()`.
63
+ - Computed defaults (function, sequence, expression, `GENERATED BY DEFAULT` identity): `.dbDefault()`. It also gets `.readOnly()` when the column is an identity column, a primary-key column, or an audit timestamp (`created_at`, `inserted_at`, `updated_at`, `modified_at`, or the same in camelCase, such as `createdAt`); other computed defaults, such as `order_date DEFAULT current_date`, stay editable. `GENERATED ALWAYS` identity and generated columns are only `.readOnly()`.
60
64
  - Leading column of a non-partial index: `.filterable()`; of a btree: also `.sortable()`. Not applied to json.
61
65
  - The text field that names a record (`name`, `title`, `number`, `sku`, `email`, `code` or `description`, else the first text field) becomes the resource's `.search(...)` when a non-partial pg_trgm index (`gin_trgm_ops` or `gist_trgm_ops`) serves it, so the [global search](client.md#global-search) finds its records by name. Without one the API would refuse the search, so it is left out; add the index and run `protobase scaffold` on a new resource, or add `.search` by hand.
62
- - Key: primary key (composite supported), else the first unique index with only `NOT NULL` columns, else the table is skipped with a warning.
66
+ - Key: primary key (composite supported), else the first unique index with only `NOT NULL` columns, else the table is skipped with a warning. A view or materialized view is skipped with a warning too, as Postgres knows no key for it: declare a resource over one by hand.
63
67
  - `deleted_at`, `removed_at`, `archived_at` (nullable timestamp/date) become `.softDelete`; `organization_id` and `tenant_id` become `.tenant`.
64
68
  - Unique indexes are listed in the doc comment above the resource.
65
69
  - Field names are the column names in snake_case; `.column()` is written only when the schema builder's default mapping would not give the column back (always for `hr."EMP_MASTER"`).
@@ -76,9 +80,11 @@ After each run, declared fields are compared with the database: a column that no
76
80
  ## `doctor`
77
81
 
78
82
  ```sh
79
- protobase doctor <connection string | --env VAR> [--config <dir>]
83
+ protobase doctor [connection string | --env VAR] [--config <dir>]
80
84
  ```
81
85
 
86
+ The URL comes as for [`scaffold`](#scaffold): the connection string, the variable `--env` names, or `DATABASE_URL`, each also read from the nearest `.env`.
87
+
82
88
  Imports `config/index.ts` and the views of `config/*/ui.ts`, as the config module has them by convention, and checks every exported resource against the database:
83
89
 
84
90
  - error: missing table or column, field type that does not fit the column (a file field needs a text column), table without a usable key, configured key not backed by a unique index
@@ -103,9 +109,11 @@ protobase dev [--port 5173] [--env DATABASE_URL] [--cache-dir <dir>] [--allowed-
103
109
 
104
110
  One process, one port: Vite serves the admin app from `@protobase/ui`'s `src/app/` (`dist/app/` when installed; `index.html` and `main.tsx`, or `main.js`; the command fails with a clear message when they are missing) and `@hono/vite-dev-server` mounts the Hono app from `createAdmin` under `/api`, supabase-js's `/api/sb` included. Open `http://localhost:<port>`; the API reference is at `/api/docs`.
105
111
 
106
- - **Database:** the URL comes from the variable named by `--env`, read from the environment or the nearest `.env` at or above the project. The connection is checked before anything starts; if it fails, the command names host, port and reason (and points to its `db:up` script when it has one). The project needs `pg` installed, because the API connects with Kysely over the project's own `pg`.
112
+ - **Secret:** a `BETTER_AUTH_SECRET` still set to the placeholder of `.env.example` (`change-me-...`) prints a warning once the server is ready, as `serve` does at start: anyone who knows it can sign session cookies.
113
+ - **Database:** the URL comes from the variable named by `--env`, read from the environment or the nearest `.env` at or above the project. The connection is checked before anything starts; if it fails, the command names host, port and reason (and, when nothing listens there, points to its `db:up` script when it has one). The project needs `pg` installed, because the API connects with Kysely over the project's own `pg`.
114
+ - **Port:** the app listens on `--port` at both `127.0.0.1` and `::1`, since `localhost` is either one depending on the runtime and the browser. When another process holds the port on either address the command stops before it starts and names that address; stop the other server or pass another `--port`.
107
115
  - **Cache:** Vite's dependency cache is `node_modules/.vite`; two dev servers sharing it can disturb each other's optimisation, so pass `--cache-dir` for a second one (the integration test does).
108
- - **Login:** real sign-in only, with the `authenticate` and `auth` exported by `protobase.config.ts` (see [Login with Better Auth](auth.md)). A project without an authenticator fails at startup with a message pointing there, one whose auth schema is behind with the tables and columns it lacks (see [`auth migration`](#auth-migration)), and one with a resource whose [events](events.md) or [history](history.md) lack their triggers, or whose [comments](comments.md) lack their table, or whose [rollup and formula fields](data-config.md#rollups-and-formulas) lack their columns or triggers, which it checks again on every reload (see [`migration`](#migration)), and one with an [AI field or action](ai.md#the-model) and no model key; there is no development login. Create the first admin with `protobase users create`.
116
+ - **Login:** real sign-in only, with the `authenticate` and `auth` exported by `protobase.config.ts` (see [Login with Better Auth](auth.md)). A project without an authenticator fails at startup with a message pointing there, one whose auth schema is behind with the tables and columns it lacks (see [`auth migration`](#auth-migration)), and one with a resource whose [events](events.md) or [history](history.md) lack their triggers, or whose [comments](comments.md) lack their table, or whose [rollup and formula fields](data-config.md#rollups-and-formulas) lack their columns or triggers, which it checks again on every reload (see [`migration`](#migration)), and one with an [AI field or action](ai.md#the-model) and no model key; there is no development login. The `login` line of the startup message says how to sign in: while the auth store has no users, it prints the exact command that creates the first admin, such as `bun run protobase users create you@example.com --generate-password` (the package manager that started `dev`, `npx` otherwise). Against a database that has users already, such as an app's hosted one, sign in as one of them or add one with a new email; its own password is set there.
109
117
  - **Mobile releases:** see [below](#mobile-releases).
110
118
  - **Jobs:** with [jobs](jobs.md) in the config it runs them in its process, once the jobs schema checks out (see [`migration`](#migration)); an edited job runs its new code from the next job on.
111
119
  - **Tunnels and other hosts:** Vite only answers `localhost` by default. `--allowed-hosts .trycloudflare.com,app.example.com` adds Host headers (a leading dot matches all subdomains). Hot reload needs no extra setting: the Vite client takes protocol, host and port from the page, so behind an HTTPS tunnel it connects over `wss` on 443 as long as the tunnel forwards WebSockets.
@@ -483,7 +491,7 @@ Run inside a project whose `protobase.config.ts` exports `auth` (Better Auth). T
483
491
 
484
492
  The password is typed at a hidden prompt with confirmation, read from stdin with `--password-stdin` (for scripts, e.g. `pass show erp | protobase users create me@example.com --password-stdin`), or generated with `--generate-password` and printed once; it must be 12 to 128 characters, the length the app requires of every new password. `--no-password` makes an account without one, which signs in by [emailed code](auth.md#emailed-sign-in-codes), passkey or a sign-in provider, as with an app whose [sign-in policy](auth.md#sign-in-policy) turns passwords off. A password is never accepted as an argument, since it would end up in shell history. `users list` prints email, role and creation date (and `disabled` for banned users), never credentials.
485
493
 
486
- `delete` asks you to type the email back (or pass `--yes`), and needs a terminal otherwise. `delete`, `set-role` and `disable` refuse to touch the last admin, so the project cannot lock itself out. `disable` bans the user and revokes their sessions; tokens already issued stop working on their next request, and `protobase token` refuses disabled users. With [MCP](auth.md#oauth-for-mcp-clients) on, it also disconnects their MCP clients. `enable` lifts the ban; the clients have to be allowed again. `protobase dev` prints "No users yet. Create the first admin with: protobase users create you@example.com" at startup while the user table is empty.
494
+ `delete` asks you to type the email back (or pass `--yes`), and needs a terminal otherwise. `delete`, `set-role` and `disable` refuse to touch the last admin, so the project cannot lock itself out. `disable` bans the user and revokes their sessions; tokens already issued stop working on their next request, and `protobase token` refuses disabled users. With [MCP](auth.md#oauth-for-mcp-clients) on, it also disconnects their MCP clients. `enable` lifts the ban; the clients have to be allowed again. `protobase dev` prints the command that creates the first admin at startup while the user table is empty (see [`dev`](#dev)).
487
495
 
488
496
  With [organizations](auth.md#organizations), `--role` is the user's global role (none by default) and `--organization` adds the new user to an organization, with `--org-role` (`owner`, `admin`, or `member`, the default) and `--app-roles` there.
489
497