@protobase/cli 0.31.1 → 0.32.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.
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "0.31.1";
2
+ var version = "0.32.0";
3
3
  //#endregion
4
4
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.31.1",
3
+ "version": "0.32.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": {
@@ -36,11 +36,11 @@
36
36
  "@better-auth/core": "^1.7.7",
37
37
  "@hono/node-server": "^2.1.3",
38
38
  "@hono/vite-dev-server": "^0.26.1",
39
- "@protobase/layout": "0.31.1",
40
- "@protobase/query": "0.31.1",
41
- "@protobase/schema": "0.31.1",
42
- "@protobase/server": "0.31.1",
43
- "@protobase/ui": "0.31.1",
39
+ "@protobase/layout": "0.32.0",
40
+ "@protobase/query": "0.32.0",
41
+ "@protobase/schema": "0.32.0",
42
+ "@protobase/server": "0.32.0",
43
+ "@protobase/ui": "0.32.0",
44
44
  "@react-email/render": "^2.1.0",
45
45
  "@scalar/hono-api-reference": "^0.12.10",
46
46
  "@tailwindcss/vite": "^4.3.3",
@@ -27,6 +27,8 @@ Run the CLI as the project does: `npx protobase <command>`, or `bun run protobas
27
27
 
28
28
  An app hosted on protobase-cloud deploys from a push to its GitHub branch instead: the `protobase-cloud` skill, which `protobase skill install` writes next to this one, covers it.
29
29
 
30
+ A project moved from Supabase with `protobase import supabase` has what the import could not convert in `supabase-import/report.md`: the `supabase-move` skill, written next to this one too, finishes it.
31
+
30
32
  ## Rules of thumb
31
33
 
32
34
  - Records live at the framework's standard addresses and API; give a resource another look through its views, layouts or a plugin, not a page with routes of its own.
@@ -448,7 +448,7 @@ The app's own pages are under the profile menu: the switcher, "Organizations" (t
448
448
 
449
449
  ## Tokens and roles
450
450
 
451
- Sign in at `POST /api/auth/sign-in/email` (or with a code or passkey), then `GET /api/auth/token` (with the session cookie) returns `{ token }`, an EdDSA JWT valid for 15 minutes, unless the [sign-in policy](#sign-in-policy) requires something the account has not set up; the keys are at `/api/auth/jwks`. Send it as `Authorization: Bearer <token>`. `/token` is the only way to a token in the browser: the `set-auth-jwt` header of Better Auth's JWT plugin is off.
451
+ Sign in at `POST /api/auth/sign-in/email` (or with a code or passkey), then `GET /api/auth/token` (with the session cookie) returns `{ token }`, an EdDSA JWT valid for 15 minutes, unless the [sign-in policy](#sign-in-policy) requires something the account has not set up; the keys are at `/api/auth/jwks`. Send it as `Authorization: Bearer <token>`. `/token` is the only way to a token in the browser: the `set-auth-jwt` header of Better Auth's JWT plugin is off. No other answer under `/api/auth` carries the session token (Better Auth's `token` and `session.token`, as in a sign-in, `get-session` or `list-sessions`): the session is the httpOnly cookie's alone, so script on the page never holds it.
452
452
 
453
453
  `betterAuthAuthenticator` maps the claims to a session: `sub` is the user id, `roles` come from the `role` claim, the session's [active role](#active-role) of those in the admin plugin's `role` column on the user (a comma separated string; the first user is always `admin`). Access rules see them as `ctx.user.roles`. Without organizations, the tenant is the configured `tenant` option, never a claim; with them, it is the organization the session works in (`org`, see [organizations](#organizations)). The key set is cached in memory: read once, again every 10 minutes (so removed keys stop being accepted), and again when a token names an unknown `kid` (a rotated key), at most once per 30 seconds however many such tokens arrive (`cache: { refreshMs, minReloadMs }`). Pass `jwksUrl` and `issuer` instead of `auth` when the API runs apart from the auth server.
454
454
 
@@ -478,6 +478,8 @@ Turns a Supabase project's database into the project in the current directory, i
478
478
 
479
479
  4. **Storage's files**: with `--storage-url https://<ref>.supabase.co` and the project's secret key in the variable `--storage-key-env` names, `SUPABASE_SERVICE_ROLE_KEY` by default, the second run, or any run after it, copies the bytes of every object in `storage.objects` from the Supabase project's Storage API into the app's [Storage file provider](supabase-storage.md#where-things-are-kept)), where [`/api/sb/storage/v1`](supabase-storage.md)) serves them, with the type and cache control the rows recorded. It streams each object, checks its byte count against the size Supabase recorded and its MD5 against the ETag where that is one, and deletes a copy that does not match. It first prints each bucket's size and stops when what is left to copy and what the provider holds exceed the provider's `max_bytes`, unless `--yes`. An object that fails does not stop the rest; the run then fails, listing them in `supabase-import/storage.md`, and a rerun copies only what the provider does not hold yet. The key goes only in the requests' headers, never in a file.
480
480
 
481
+ An agent with the `supabase-move` skill of [`skill install`](#skill) finishes what the report leaves: it rewrites each item, checking the project's database for the extensions an item needs, and runs `doctor` and the typecheck until both pass, leaving the values of Vault's secrets for you to enter.
482
+
481
483
  Remove `supabase-import/` to import again. Signing in Supabase's users with Protobase's auth is not part of this command yet.
482
484
 
483
485
  ## `mobile`
@@ -513,7 +515,7 @@ curl -H "Authorization: Bearer $(protobase token me@x)" http://localhost:5173/ap
513
515
  protobase skill install [name]
514
516
  ```
515
517
 
516
- Copies the agent skills of this CLI's version into the current project, or only the one `name` names. `protobase`, the protobase agent skill, goes to `.agents/skills/protobase/` (read by Codex, Cursor, OpenCode and Amp) and `.claude/skills/protobase/` (read by Claude Code): a short `SKILL.md` with the everyday workflow and the checks before calling a change done, and the guides and reference of this version as files it points to. `protobase-cloud` goes to `.agents/skills/protobase-cloud/` and `.claude/skills/protobase-cloud/`: how an app hosted on protobase-cloud deploys from GitHub, how to check that a change went live, and why a deploy failed. Each replaces an earlier copy, and refuses to touch a folder of its name that holds another skill. Commit the folders, and run the command again after upgrading the `@protobase` packages. The skills also ship in `node_modules/@protobase/cli/skills`, where the `skills` CLI's `experimental_sync` finds it.
518
+ Copies the agent skills of this CLI's version into the current project, or only the one `name` names. `protobase`, the protobase agent skill, goes to `.agents/skills/protobase/` (read by Codex, Cursor, OpenCode and Amp) and `.claude/skills/protobase/` (read by Claude Code): a short `SKILL.md` with the everyday workflow and the checks before calling a change done, and the guides and reference of this version as files it points to. `protobase-cloud` goes to `.agents/skills/protobase-cloud/` and `.claude/skills/protobase-cloud/`: how an app hosted on protobase-cloud deploys from GitHub, how to check that a change went live, and why a deploy failed. `supabase-move` goes beside them: it has an agent work through `supabase-import/report.md` after [`import supabase`](#import-supabase), item by item, until `doctor` and the app's typecheck pass. Each replaces an earlier copy, and refuses to touch a folder of its name that holds another skill. Commit the folders, and run the command again after upgrading the `@protobase` packages. The skills also ship in `node_modules/@protobase/cli/skills`, where the `skills` CLI's `experimental_sync` finds it.
517
519
 
518
520
  ## ERP example
519
521
 
@@ -0,0 +1,113 @@
1
+ ---
2
+ name: supabase-move
3
+ description: Finish a move from Supabase to Protobase after `protobase import supabase`, item by item from its report (supabase-import/report.md), until `protobase doctor` and the app's typecheck pass. Use it when a project has supabase-import/report.md, or when asked to finish or complete a Supabase import.
4
+ ---
5
+
6
+ # Finishing a move from Supabase
7
+
8
+ `protobase import supabase` converts what it can and writes `supabase-import/report.md` with the rest. This skill works through that report, one `## ` section at a time, in the report's order. The `protobase` skill beside this one has the guides and reference it links to.
9
+
10
+ ## Rules
11
+
12
+ - **Never invent data.** Copy only what the Supabase project states: a URL, a header, a schedule, a column's value. A secret's value is never in the report or the code: leave it for the user to enter. A column with nothing to go on stays NULL; add no `DEFAULT` that stands in for "unknown".
13
+ - **Rewrite only what the project's database lacks.** Before rewriting the use of an extension, check that database, not the report alone: a Pro or Business app's own Postgres runs every extension it had on Supabase, and there pg_net, pg_cron, pgmq and Vault stay as they are.
14
+
15
+ ```sh
16
+ psql "$DATABASE_URL" -Atc "select name, installed_version is not null from pg_available_extensions where name in ('pg_net', 'pg_cron', 'pgmq', 'supabase_vault') order by 1"
17
+ ```
18
+
19
+ An extension that is listed but not installed is created by a migration (`create extension if not exists <name>;`), not rewritten.
20
+ - **Database changes are new migrations** in the project's migrations folder, numbered after the last one, applied with the project's own migrate script (`db:migrate`). Never edit the import's `NNN_supabase_schema.sql` once it is applied, and never change the database by hand.
21
+ - **Never loosen a check** to make it pass: not the scan guard, not `strict`, not a `// @ts-ignore`.
22
+ - When a conversion needs a decision only the user can make, such as a paid service to replace one Supabase ran, stop on that item, say what it needs, and go on with the others.
23
+
24
+ ## The loop
25
+
26
+ 1. Read `supabase-import/report.md` and work through its sections below.
27
+ 2. `protobase migration`, then the project's migrate script: it writes the jobs schema, the events' capture and the rest of what the config now enables.
28
+ 3. The app's typecheck (`tsc --noEmit`, or its `typecheck` script).
29
+ 4. `protobase doctor --env DATABASE_URL`.
30
+ 5. Fix what 3 and 4 report and go back to 2, until both pass.
31
+ 6. Tell the user what is theirs to do: the variables to fill in, items you stopped on, and `--storage-url` if the files are not copied yet.
32
+
33
+ ## The report, section by section
34
+
35
+ ### Rows loaded
36
+
37
+ Nothing to do: each table's count matched the source before the load committed.
38
+
39
+ ### Made again
40
+
41
+ Nothing to do: the project's database has these extensions and the load made each item again there.
42
+
43
+ ### Recurring jobs
44
+
45
+ The import wrote these in `jobs/`. Wire `jobs/index.ts` into `protobase.config.ts`'s `jobs` if the report says it is not, then run step 2 of the loop. See [Jobs](../protobase/references/reference/jobs.md#recurring-jobs).
46
+
47
+ ### Cron jobs
48
+
49
+ Each line is a pg_cron job, its schedule, its command and why it did not come over.
50
+
51
+ - Calls `net.http_get` or `net.http_post`, and the database has pg_net: schedule it again with `cron.schedule` in a migration, as it was, when the database has pg_cron, or keep its SQL as a recurring job when it does not.
52
+ - Calls pg_net, and the database has none: a recurring job in `jobs/<name>.ts` with `defineJob({ name, schedule, timezone, run })`, of the same name and schedule, whose `run` makes the same request with `fetch`: the same method, URL, headers and body. A header or URL that read a Vault secret reads `requireEnv('<NAME>')` instead (see Vault secrets). Throw when the response is not `ok`, so the failure shows. Export it from `jobs/index.ts`.
53
+ - A schedule recurring jobs do not take, such as `30 seconds`: the closest cron expression only if the user agrees; otherwise leave it and say so.
54
+ - Inactive: ask the user whether it should run before making it a job.
55
+
56
+ ### Live tables
57
+
58
+ Nothing to do but step 2 of the loop, which writes their capture triggers.
59
+
60
+ ### Realtime tables
61
+
62
+ Give each table a resource with `.live()` in `config/` where the app listens to its changes (look for `postgres_changes` with this table in the app's client code). A table without a primary key needs one first, as a migration, only when the user agrees. See [Supabase Realtime](../protobase/references/reference/supabase-realtime.md).
63
+
64
+ ### Vault secrets
65
+
66
+ Each secret moves to an environment variable the user enters again. Name it after the secret, upper case (`stripe_key` → `STRIPE_KEY`), and:
67
+
68
+ - add it to `.env.example` (create it if missing) with an empty value and the secret's description as a comment;
69
+ - where code read it (`vault.decrypted_secrets` in SQL, a function or a cron job), read `requireEnv('<NAME>')` in TypeScript instead. SQL that needs the secret moves into a job or function that does;
70
+ - never write the value anywhere, and never put one in `.env.example`.
71
+
72
+ ### pgmq queues
73
+
74
+ With pgmq in the database, make each queue again in a migration (`select pgmq.create('<name>')`, or `pgmq.create_partitioned`); the user sends the messages again, since the report gives only their count. Without pgmq, move the queue's producers and consumers to a Protobase job: `defineJob` with the consumer's work as `run`, and `jobs.enqueue('<name>', payload)` where SQL called `pgmq.send`. See [Jobs](../protobase/references/reference/jobs.md#from-sql).
75
+
76
+ ### Extensions left out
77
+
78
+ For each, find what uses it: `grep -n '<extension>\|<schema>\.' db/migrations/*supabase_schema.sql` and the app's code. A use the app's code can take over (`pgjwt` → `jose` in a function, `http` → `fetch` in a job, `pg_hashids` → an npm package) moves there. A use that needs the extension itself, such as PostGIS columns, needs a database that has it: stop on it and tell the user.
79
+
80
+ ### To convert
81
+
82
+ - A hypertable: a plain table, or one partitioned by time with a migration; its rows came over empty, so the user copies them from Supabase with `INSERT … SELECT`. Do not make them up.
83
+ - A function in plv8, plls or plcoffee: rewrite it in plpgsql in a migration, keeping its name, arguments and result; or as a Protobase API function when nothing in SQL calls it.
84
+
85
+ ### HTTP triggers
86
+
87
+ Each line is a trigger, its table, and the function it calls (`supabase_functions.http_request` for a Database Webhook). The report lists them only when the database lacked pg_net; check again, as above.
88
+
89
+ Without pg_net, replace each with an event and a subscription:
90
+
91
+ 1. On the table's resource, declare the event the trigger fired on: `e.created()`, `e.updated()`, `e.deleted()` or `e.crud()`, with a `when` for its `WHEN` clause. See [Events](../protobase/references/reference/events.md).
92
+ 2. Export a `subscription(...)` from the config module with that event, and as target: `function: '<name>'` when the URL was one of the app's own Edge Functions (`.../functions/v1/<name>`), otherwise `url` with the URL the trigger named. Copy its headers into `headers`, a secret one from the environment. A receiver that reads Supabase's payload (`type`, `table`, `schema`, `record`, `old_record`) gets it through `body`. See [Webhooks](../protobase/references/reference/webhooks.md).
93
+ 3. Drop the trigger, and a trigger function only it used, in a migration.
94
+
95
+ ### Storage files
96
+
97
+ Ask the user to run `protobase import supabase --storage-url https://<ref>.supabase.co` with their project's secret key in `SUPABASE_SERVICE_ROLE_KEY`, unless `supabase-import/storage.md` says the files are copied. Never ask for the key in the conversation.
98
+
99
+ ### Edge Functions
100
+
101
+ `supabase/functions` keeps the Deno originals, which the app no longer runs: add `supabase` to the `exclude` of `tsconfig.json` so the typecheck leaves them out, and remove the folder only when the user says so. Look in each for `waitUntil(`: work in it that can outlast about 10 seconds after the response, such as sending mail, calling a slow API or a loop over many records, moves into a job enqueued instead (`await job.enqueue(db, payload)`), since a host stops an idle app and loses work still running. See [Functions moved from Supabase](../protobase/references/guides/api-functions.md#functions-moved-from-supabase).
102
+
103
+ ### Packages added
104
+
105
+ Run the project's install (`npm install`, `bun install`, ...). A `npm:@jsr/...` range needs `@jsr:registry=https://npm.jsr.io` in `.npmrc`.
106
+
107
+ ### Edge Function code to rewrite
108
+
109
+ Each line is `<file>:<line>: <what>`. Rewrite each for Node and Bun as [Deno and Supabase's runtime](references/deno.md) says, keeping what the code does.
110
+
111
+ ### Indexes the scan guard needs
112
+
113
+ Each `error` doctor printed ends in `fix: create index ...`. Add each index in a migration of its own, apply it, and run doctor again.
@@ -0,0 +1,33 @@
1
+ # Deno and Supabase's runtime, for Node and Bun
2
+
3
+ What the conversion leaves in `functions/`, by the note the report gives, and what replaces it. A function runs under Node and Bun with Web APIs (`fetch`, `Request`, `Response`, `crypto.subtle`, `URL`) and Node's built-in modules.
4
+
5
+ ## Imports
6
+
7
+ | Note | Rewrite |
8
+ | --- | --- |
9
+ | `import of https://deno.land/std@.../<module>/...` | The same module from JSR, `@std/<module>`, in `package.json` as `"@std/<module>": "npm:@jsr/std__<module>@^1"` with `@jsr:registry=https://npm.jsr.io` in `.npmrc`; or Node's own, where it has one (`std/path` → `node:path`, `std/encoding/base64` → `Buffer.from(x).toString('base64')`, `std/crypto` → `crypto.subtle`). |
10
+ | `import of https://deno.land/x/<module>...` | The npm package of the same library, when its README names one; otherwise a maintained npm package that does the same, which the user agrees to. Take its version from `npm view <package> version`, never from memory. A database client (`deno.land/x/postgres`) becomes the function's `db` (Kysely on the app's database). |
11
+ | `import of https://<other host>/...` | The npm package the URL serves, by the same rule. |
12
+
13
+ ## Deno
14
+
15
+ | Note | Rewrite |
16
+ | --- | --- |
17
+ | `Deno.readTextFile`, `Deno.readFile`, `Deno.writeTextFile`, `Deno.writeFile` | `readFile`, `writeFile` of `node:fs/promises`. A file beside the function: `new URL('./<file>', import.meta.url)`. Bundled apps have no writable folder: data a function wrote to disk goes to a table or the app's Storage instead. |
18
+ | `Deno.env.toObject` | `process.env`. |
19
+ | `Deno.cwd`, `Deno.args`, `Deno.exit` | `process.cwd()`; no arguments; throw an error instead of exiting. |
20
+ | `Deno.openKv` | A table, in a migration, in a schema named for what it keeps (`create table <schema>.<name> (key text[] primary key, value jsonb not null, expires_at timestamptz)`), read and written with the function's `db`. `expireIn` becomes `expires_at`, and readers skip expired rows. Deno KV's data does not come over: start empty, unless the user exports it. |
21
+ | `Deno.upgradeWebSocket` | A function answers HTTP only. Move the messages to Realtime broadcast on a channel, which supabase-js reaches at `/api/sb/realtime/v1` (see [Supabase Realtime](../../protobase/references/reference/supabase-realtime.md)), and change the client to it; when that does not fit, stop on it and tell the user. |
22
+ | `Deno.serve(...)` or `serve(...)`, `which Protobase does not run` | Make the file's default export `{ fetch: handler }` itself, once per function, in its `index.ts`. |
23
+ | `no Deno.serve or default export to serve` | Find the handler and default-export `{ fetch: handler }`. |
24
+ | `<dir> has no index.ts, so it was not imported` | Move its entry point to `index.ts` in `supabase/functions/<name>`, and convert it as the import did: rerun it in a scratch checkout, or apply this table by hand. |
25
+ | `asks for <package> <range>, another file for <range>` | Make both files work with one version, the range `package.json` has. |
26
+
27
+ ## Supabase's runtime
28
+
29
+ | Note | Rewrite |
30
+ | --- | --- |
31
+ | `Supabase.ai.Session('gte-small')` | The same model under Node with `@huggingface/transformers`: `const embed = await pipeline('feature-extraction', 'Supabase/gte-small')` once per process, then `Array.from((await embed(text, { pooling: 'mean', normalize: true })).data)` where the code called `session.run(text, { mean_pool: true, normalize: true })`. It gives the same 384 numbers, so stored embeddings keep matching. |
32
+ | `Supabase.ai.Session('<an LLM>')` | A call to an OpenAI-compatible chat completions endpoint with `fetch`, its URL, key and model from `requireEnv`; the user picks the provider and fills them in. |
33
+ | `EdgeRuntime.<anything but waitUntil>` | Drop it, or its Node equivalent (`process.version` for the version). |