@protobase/cli 0.133.10 → 0.133.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.
- package/dist/cli/package.js +1 -1
- package/dist/dev/dev-port.js +31 -7
- package/dist/dev/dev-relay.d.ts +1 -1
- package/dist/dev/dev-relay.js +31 -18
- package/dist/dev/realtime-binary.js +7 -3
- package/package.json +8 -8
- package/skills/protobase/references/reference/cli.md +2 -2
- package/skills/protobase/references/reference/realtime-relay.md +1 -1
package/dist/cli/package.js
CHANGED
package/dist/dev/dev-port.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { protobaseFolder } from "../project/protobase-folder.js";
|
|
2
2
|
import { heldOn } from "./loopback.js";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import {
|
|
4
|
+
import { randomUUID } from "node:crypto";
|
|
5
|
+
import { link, mkdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
|
|
5
6
|
//#region src/dev/dev-port.ts
|
|
6
7
|
/** Where `protobase dev` keeps the project's port: `.protobase/` is this machine's and ignores itself in git. */
|
|
7
8
|
const devPortFile = path.join(protobaseFolder, "dev-port");
|
|
@@ -24,10 +25,35 @@ const readSavedPort = async (projectDir) => {
|
|
|
24
25
|
const port = Number(trimmed);
|
|
25
26
|
return port >= 1 && port <= 65535 ? port : void 0;
|
|
26
27
|
};
|
|
28
|
+
const writeTemporary = async (projectDir, port) => {
|
|
29
|
+
await mkdir(path.join(projectDir, protobaseFolder), { recursive: true });
|
|
30
|
+
const temporary = path.join(projectDir, `${devPortFile}.${randomUUID()}.tmp`);
|
|
31
|
+
await writeFile(temporary, `${port}\n`);
|
|
32
|
+
return temporary;
|
|
33
|
+
};
|
|
27
34
|
const savePort = async (projectDir, port) => {
|
|
28
35
|
if (await readSavedPort(projectDir) === port) return;
|
|
29
|
-
await
|
|
30
|
-
await
|
|
36
|
+
const temporary = await writeTemporary(projectDir, port);
|
|
37
|
+
await rename(temporary, path.join(projectDir, devPortFile));
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Saves `port` only when no port file exists yet, and returns the project's port: `port`, or the one another run
|
|
41
|
+
* published first. Linking fails when the file exists, so of two first runs started together only one publishes.
|
|
42
|
+
*/
|
|
43
|
+
const publishPort = async (projectDir, port) => {
|
|
44
|
+
const temporary = await writeTemporary(projectDir, port);
|
|
45
|
+
try {
|
|
46
|
+
await link(temporary, path.join(projectDir, devPortFile));
|
|
47
|
+
return port;
|
|
48
|
+
} catch (error) {
|
|
49
|
+
if (error.code !== "EEXIST") throw error;
|
|
50
|
+
} finally {
|
|
51
|
+
await unlink(temporary);
|
|
52
|
+
}
|
|
53
|
+
const saved = await readSavedPort(projectDir);
|
|
54
|
+
if (saved !== void 0) return saved;
|
|
55
|
+
await savePort(projectDir, port);
|
|
56
|
+
return port;
|
|
31
57
|
};
|
|
32
58
|
/** A random port in `randomPorts` that no process holds on either loopback address, trying a fixed number of them. */
|
|
33
59
|
const pickFreePort = async (held = heldOn, random = Math.random) => {
|
|
@@ -50,9 +76,7 @@ const devPort = async (projectDir, chosen, pick = pickFreePort) => {
|
|
|
50
76
|
}
|
|
51
77
|
const saved = await readSavedPort(projectDir);
|
|
52
78
|
if (saved !== void 0) return saved;
|
|
53
|
-
|
|
54
|
-
await savePort(projectDir, picked);
|
|
55
|
-
return picked;
|
|
79
|
+
return publishPort(projectDir, await pick());
|
|
56
80
|
};
|
|
57
81
|
//#endregion
|
|
58
|
-
export { devAddress, devPort, devPortFile, pickFreePort, randomPorts, readSavedPort, savePort };
|
|
82
|
+
export { devAddress, devPort, devPortFile, pickFreePort, publishPort, randomPorts, readSavedPort, savePort };
|
package/dist/dev/dev-relay.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "@protobase/schema";
|
|
2
2
|
import "@protobase/config";
|
|
3
3
|
//#region src/dev/dev-relay.d.ts
|
|
4
|
-
/** Ends the relay protobase dev started, when the dev server closes. */
|
|
4
|
+
/** Ends the relay protobase dev started, when the dev server closes, once a start under way has finished. */
|
|
5
5
|
export declare const stopDevRelay: () => Promise<void>;
|
|
6
6
|
//#endregion
|
package/dist/dev/dev-relay.js
CHANGED
|
@@ -5,6 +5,13 @@ import { randomBytes } from "node:crypto";
|
|
|
5
5
|
import { checkRelayOptions, defaultRelayChannels } from "@protobase/server";
|
|
6
6
|
//#region src/dev/dev-relay.ts
|
|
7
7
|
const store = globalThis;
|
|
8
|
+
const devRelay = () => store.__protobaseDevRelay ??= { queue: Promise.resolve() };
|
|
9
|
+
const inTurn = (step) => {
|
|
10
|
+
const state = devRelay();
|
|
11
|
+
const result = state.queue.then(() => step(state));
|
|
12
|
+
state.queue = result.then(() => void 0, () => void 0);
|
|
13
|
+
return result;
|
|
14
|
+
};
|
|
8
15
|
const devLimits = {
|
|
9
16
|
connections: 1e3,
|
|
10
17
|
channels_per_ticket: 200,
|
|
@@ -16,8 +23,26 @@ const devKeys = () => store.__protobaseDevRelayKeys ??= {
|
|
|
16
23
|
ticketKey: devKey(),
|
|
17
24
|
presenceKey: devKey()
|
|
18
25
|
};
|
|
19
|
-
const
|
|
20
|
-
|
|
26
|
+
const stopRunning = async (state) => {
|
|
27
|
+
const running = state.running;
|
|
28
|
+
state.running = void 0;
|
|
29
|
+
await running?.relay.stop();
|
|
30
|
+
};
|
|
31
|
+
const relayFor = async (state, entry) => {
|
|
32
|
+
if (state.running?.entry === entry) return state.running;
|
|
33
|
+
await stopRunning(state);
|
|
34
|
+
const port = await freePort();
|
|
35
|
+
const binary = await realtimeBinary();
|
|
36
|
+
const running = {
|
|
37
|
+
entry,
|
|
38
|
+
url: relayUrl(port),
|
|
39
|
+
relay: await startRelay(binary, port, JSON.parse(entry), (code) => relayEnded(state, running, code))
|
|
40
|
+
};
|
|
41
|
+
state.running = running;
|
|
42
|
+
return running;
|
|
43
|
+
};
|
|
44
|
+
const relayEnded = (state, ended, code) => {
|
|
45
|
+
if (state.running === ended) state.running = void 0;
|
|
21
46
|
process.stderr.write(`error: the relay of protobase dev ended (exit code ${code}); save a file of the project to start it again\n`);
|
|
22
47
|
};
|
|
23
48
|
/**
|
|
@@ -54,31 +79,19 @@ const withDevRelay = async (config, devUrl, { views, models }) => {
|
|
|
54
79
|
}),
|
|
55
80
|
limits: devLimits
|
|
56
81
|
});
|
|
57
|
-
|
|
58
|
-
await stopDevRelay();
|
|
59
|
-
const port = await freePort();
|
|
60
|
-
store.__protobaseDevRelay = {
|
|
61
|
-
entry,
|
|
62
|
-
url: relayUrl(port),
|
|
63
|
-
relay: await startRelay(await realtimeBinary(), port, JSON.parse(entry), relayEnded)
|
|
64
|
-
};
|
|
65
|
-
}
|
|
82
|
+
const running = await inTurn((state) => relayFor(state, entry));
|
|
66
83
|
return {
|
|
67
84
|
...config,
|
|
68
85
|
realtime: {
|
|
69
86
|
...config.realtime,
|
|
70
87
|
relay: {
|
|
71
88
|
...options,
|
|
72
|
-
url:
|
|
89
|
+
url: running.url
|
|
73
90
|
}
|
|
74
91
|
}
|
|
75
92
|
};
|
|
76
93
|
};
|
|
77
|
-
/** Ends the relay protobase dev started, when the dev server closes. */
|
|
78
|
-
const stopDevRelay =
|
|
79
|
-
const running = store.__protobaseDevRelay;
|
|
80
|
-
delete store.__protobaseDevRelay;
|
|
81
|
-
await running?.relay.stop();
|
|
82
|
-
};
|
|
94
|
+
/** Ends the relay protobase dev started, when the dev server closes, once a start under way has finished. */
|
|
95
|
+
const stopDevRelay = () => inTurn(stopRunning);
|
|
83
96
|
//#endregion
|
|
84
97
|
export { stopDevRelay, withDevRelay };
|
|
@@ -51,9 +51,13 @@ const realtimeBinary = async ({ env = process.env, release = realtimeRelease, ca
|
|
|
51
51
|
if (actual !== expected) throw new Error(`Protobase Realtime from ${url} has sha256 ${actual}, not the pinned ${expected}, so protobase dev does not run it`);
|
|
52
52
|
await mkdir(versionDir, { recursive: true });
|
|
53
53
|
const partial = `${file}.${randomBytes(6).toString("hex")}.partial`;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
try {
|
|
55
|
+
await writeFile(partial, bytes);
|
|
56
|
+
await chmod(partial, 493);
|
|
57
|
+
await rename(partial, file);
|
|
58
|
+
} finally {
|
|
59
|
+
await rm(partial, { force: true }).catch(() => void 0);
|
|
60
|
+
}
|
|
57
61
|
return file;
|
|
58
62
|
};
|
|
59
63
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.133.
|
|
3
|
+
"version": "0.133.12",
|
|
4
4
|
"description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -43,13 +43,13 @@
|
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@better-auth/core": "^1.7.12",
|
|
45
45
|
"@hono/node-server": "^2.1.3",
|
|
46
|
-
"@protobase/config": "0.133.
|
|
47
|
-
"@protobase/layout": "0.133.
|
|
48
|
-
"@protobase/query": "0.133.
|
|
49
|
-
"@protobase/schema": "0.133.
|
|
50
|
-
"@protobase/server": "0.133.
|
|
51
|
-
"@protobase/ui": "0.133.
|
|
52
|
-
"@protobase/workflows": "0.133.
|
|
46
|
+
"@protobase/config": "0.133.12",
|
|
47
|
+
"@protobase/layout": "0.133.12",
|
|
48
|
+
"@protobase/query": "0.133.12",
|
|
49
|
+
"@protobase/schema": "0.133.12",
|
|
50
|
+
"@protobase/server": "0.133.12",
|
|
51
|
+
"@protobase/ui": "0.133.12",
|
|
52
|
+
"@protobase/workflows": "0.133.12",
|
|
53
53
|
"@react-email/render": "^2.1.0",
|
|
54
54
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
55
55
|
"@sentry/vite-plugin": "^11.10.0",
|
|
@@ -202,7 +202,7 @@ One port, two processes: Vite serves the admin app from `@protobase/ui`'s `src/a
|
|
|
202
202
|
- **Login:** real sign-in only, with the config's `auth`, on by default, or its `authenticate` for tokens of an auth server elsewhere (see [protobase.config.ts](config.md) and [Login with Better Auth](auth.md)). A project with sign-in off and no authenticator fails at startup with a message pointing there, as does one with sign-in on and no `PROTOBASE_SECRET`, one whose auth store has not applied every migration of this version, naming them (see [`auth migration`](#auth-migration)), one with a resource over a table of the auth store, 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. A `warning` line follows for each way the auth store's tables differ from what the app's sign-in needs, such as a column dropped by hand: the one place Protobase compares them, since `serve` reads the store's record of [migrations](auth.md#migrations) alone.
|
|
203
203
|
- **Mobile releases:** see [below](#mobile-releases).
|
|
204
204
|
- **Jobs:** with [jobs](jobs.md) in the config it runs them in the API's process, once the jobs schema checks out (see [`migration`](#migration)); an edited job runs its new code from the next job on. `--no-jobs` runs none of them and delivers none of the app's [events](events.md), webhooks or pushes, for a dev server on the database of a hosted app that already runs them; jobs are still enqueued, for that app to run, and the startup message says `jobs off`.
|
|
205
|
-
- **Realtime relay:** with [`realtime.relay`](realtime-relay.md) and no `url`, it runs the relay for the app, Protobase Realtime downloaded from its
|
|
205
|
+
- **Realtime relay:** with [`realtime.relay`](realtime-relay.md) and no `url`, it runs the relay for the app, Protobase Realtime downloaded from its release on first use, its sha256 checked and cached in the user's cache folder (`PROTOBASE_REALTIME_BINARY` runs a build of your own), gives the app its address and keys, and stops it with the dev server (see [Local development](realtime-relay.md#local-development)).
|
|
206
206
|
- **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). The API's WebSockets, such as an [API function](../guides/api-functions.md#websockets)'s, pass the same check: an upgrade with another Host header is refused with `403`. 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.
|
|
207
207
|
- **Project discovery**, by convention: `config/index.ts` exports the resources (and views), and every `config/*/ui.ts` export that is not already exported by the index is added as a view. Each `functions/<name>.ts` (or `functions/<name>/index.ts`) is an [API function](../guides/api-functions.md) at `/api/functions/<name>`. `protobase.config.ts` (or `protobase.config.json`) in the project root describes the rest as data, and the jobs, hooks and other code it names are found by their paths; see [protobase.config.ts](config.md). Without it, the app runs on the defaults.
|
|
208
208
|
- **Project UI:** the app imports `protobase.ui.tsx` from the project root, with hot reload, when it exists (see [Custom components](custom-components.md)): the same contract as the plugin `protobase build` makes of it, built into the dev page instead. Layout files are checked as they load, as `protobase build` checks them.
|
|
@@ -512,7 +512,7 @@ Serves the API of a bundle from `protobase build` and owns the process around it
|
|
|
512
512
|
| `PROTOBASE_SENTRY_DSN` | the DSN of a Sentry-compatible error tracker the app's server and admin app send their errors to, after the config's `errorReporting` ([Error reporting](api.md#error-reporting)); without it nothing is sent |
|
|
513
513
|
| `PROTOBASE_REALTIME_URL`, `PROTOBASE_REALTIME_APP`, `PROTOBASE_REALTIME_API_KEY`, `PROTOBASE_REALTIME_TICKET_KEY`, `PROTOBASE_REALTIME_PRESENCE_KEY` | the address, the app's id, its API and ticket keys and its presence key of [Protobase Realtime](realtime-relay.md#from-the-platform), the WebSocket relay, each where the config's `realtime.relay` leaves it out; without `realtime.relay` or `PROTOBASE_REALTIME_ENABLED` the relay stays off |
|
|
514
514
|
| `PROTOBASE_REALTIME_ENABLED` | `true` when the platform moves the app to [Realtime](realtime-relay.md#from-the-platform), with the channels of `realtime.relay` or else of its live resources whose conversation page has `members`; `true` for an app with neither stops the server. Unset or empty is `false`; any other value stops the server |
|
|
515
|
-
| `PROTOBASE_REALTIME_BINARY`, `PROTOBASE_REALTIME_DOWNLOAD_URL` | `protobase dev` only: the path of a [Realtime](realtime-relay.md#local-development) build of your own to run, unchecked, in place of the pinned release it downloads, and the address it downloads that release from, default
|
|
515
|
+
| `PROTOBASE_REALTIME_BINARY`, `PROTOBASE_REALTIME_DOWNLOAD_URL` | `protobase dev` only: the path of a [Realtime](realtime-relay.md#local-development) build of your own to run, unchecked, in place of the pinned release it downloads, and the address it downloads that release from, default the Protobase Realtime releases |
|
|
516
516
|
| `PROTOBASE_MAP_STYLE_URL` | the URL of the MapLibre style the record page's [maps](ui-config.md#maps) are drawn with, after the config's `maps`; without it there are no maps |
|
|
517
517
|
| `PROTOBASE_SOURCES` | other Protobase APIs whose resources the app draws as its own, a JSON list of `{ "url", "label", "resources", "roles"? }` after the config's `remoteResources` ([Remote resources](remote-resources.md#declaring-a-source)) |
|
|
518
518
|
| `PROTOBASE_FILES_<NAME>`, `PROTOBASE_FILES_RETENTION`, `PROTOBASE_FILES_SECRET` | [file providers](files.md#providers) and their settings, over `files` in the config; a bucket's credentials in `PROTOBASE_FILES_<NAME>_ACCESS_KEY_ID` and `_SECRET_ACCESS_KEY` |
|
|
@@ -85,7 +85,7 @@ export default defineConfig({
|
|
|
85
85
|
|
|
86
86
|
## Local development
|
|
87
87
|
|
|
88
|
-
[`protobase dev`](cli.md#dev) runs a relay of its own when `realtime.relay` has no `url`, such as with `RELAY_URL` unset in `.env`, so local realtime needs nothing installed and no second command. On first use it downloads the Protobase Realtime build for this machine from the
|
|
88
|
+
[`protobase dev`](cli.md#dev) runs a relay of its own when `realtime.relay` has no `url`, such as with `RELAY_URL` unset in `.env`, so local realtime needs nothing installed and no second command. On first use it downloads the Protobase Realtime build for this machine from the release the CLI pins, checks it against the sha256 the CLI pins for it, and caches it in `protobase/realtime/<version>/` of the user's cache folder (`XDG_CACHE_HOME` or `~/.cache` on Linux, `~/Library/Caches` on macOS, `%LOCALAPPDATA%` on Windows); each start checks the cached file again and downloads it anew when it no longer matches. An app without `realtime.relay`, or with a `url`, downloads nothing. `PROTOBASE_REALTIME_BINARY` runs a build of your own instead, unchecked, such as on a machine without a release build or without the network, and `PROTOBASE_REALTIME_DOWNLOAD_URL` downloads the release from a mirror that keeps its `v<version>/<asset>` paths.
|
|
89
89
|
|
|
90
90
|
<gap>`protobase dev` cannot download Realtime on Windows on Arm because a release build for it is not implemented.</gap>
|
|
91
91
|
|