@protobase/cli 0.127.2 → 0.127.4

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.127.2";
2
+ var version = "0.127.4";
3
3
  //#endregion
4
4
  export { version };
@@ -1,5 +1,5 @@
1
1
  import { relayAppEntry } from "../relay/app-entry.js";
2
- import { relayBinary } from "./relay-binary.js";
2
+ import { realtimeBinary } from "./realtime-binary.js";
3
3
  import { freePort, relayUrl, startRelay } from "./relay-process.js";
4
4
  import { randomBytes } from "node:crypto";
5
5
  import { checkRelayOptions, defaultRelayChannels } from "@protobase/server";
@@ -22,11 +22,11 @@ const relayEnded = (code) => {
22
22
  };
23
23
  /**
24
24
  * The config with a relay of its own when `realtime.relay` names none: without a `url`, protobase dev runs the relay
25
- * from its npm package for the app at `devUrl`, with keys it makes unless the config sets them, the presence key too, and gives the app its
25
+ * from the pinned Protobase Realtime release (`realtimeBinary`) for the app at `devUrl`, with keys it makes unless the config sets them, the presence key too, and gives the app its
26
26
  * address and keys; its apps file declares the events of `views`' typing conversation pages too, and its channels default to those of the conversation pages with members (`defaultRelayChannels`). It starts on the first load whose config has `realtime.relay`, and again when an edit changes the
27
27
  * app's entry in its apps file; a config without `realtime.relay`, or one with a `url`, stops it.
28
28
  */
29
- const withDevRelay = async (config, projectDir, devUrl, { views, models }) => {
29
+ const withDevRelay = async (config, devUrl, { views, models }) => {
30
30
  const relay = config.realtime?.relay;
31
31
  if (!relay || relay.url) {
32
32
  await stopDevRelay();
@@ -60,7 +60,7 @@ const withDevRelay = async (config, projectDir, devUrl, { views, models }) => {
60
60
  store.__protobaseDevRelay = {
61
61
  entry,
62
62
  url: relayUrl(port),
63
- relay: await startRelay(await relayBinary(projectDir), port, JSON.parse(entry), relayEnded)
63
+ relay: await startRelay(await realtimeBinary(), port, JSON.parse(entry), relayEnded)
64
64
  };
65
65
  }
66
66
  return {
package/dist/dev/entry.js CHANGED
@@ -21,7 +21,7 @@ const relayApp = {
21
21
  views: relayExports?.views.map((view) => view.toModel()) ?? [],
22
22
  models: relayExports?.resources.map((resource) => resource.toModel()) ?? []
23
23
  };
24
- const config = await withDevRelay(loaded, projectDir, process.env.PROTOBASE_DEV_URL, relayApp);
24
+ const config = await withDevRelay(loaded, process.env.PROTOBASE_DEV_URL, relayApp);
25
25
  const database = devDatabase(projectDir);
26
26
  const { db } = database;
27
27
  const project = await buildProject(config, database);
@@ -0,0 +1,60 @@
1
+ import { realtimeAsset, realtimeRelease } from "./realtime-release2.js";
2
+ import { userCacheDir } from "./user-cache-dir.js";
3
+ import path from "node:path";
4
+ import { createHash, randomBytes } from "node:crypto";
5
+ import { chmod, mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
6
+ //#region src/dev/realtime-binary.ts
7
+ const realtimeBinaryVariable = "PROTOBASE_REALTIME_BINARY";
8
+ const realtimeDownloadVariable = "PROTOBASE_REALTIME_DOWNLOAD_URL";
9
+ const sha256 = (bytes) => createHash("sha256").update(bytes).digest("hex");
10
+ const readCached = async (file) => {
11
+ try {
12
+ return await readFile(file);
13
+ } catch (error) {
14
+ if (error.code === "ENOENT") return;
15
+ throw error;
16
+ }
17
+ };
18
+ const download = async (url) => {
19
+ const failed = (reason) => /* @__PURE__ */ new Error(`protobase dev could not download Protobase Realtime from ${url} (${reason}): check the connection, or set ${realtimeBinaryVariable} to a binary of your own`);
20
+ let response;
21
+ try {
22
+ response = await fetch(url);
23
+ } catch (error) {
24
+ if (error instanceof TypeError) throw failed("no connection");
25
+ throw error;
26
+ }
27
+ if (!response.ok) throw failed(`HTTP ${response.status}`);
28
+ return new Uint8Array(await response.arrayBuffer());
29
+ };
30
+ /**
31
+ * The path of the Protobase Realtime binary protobase dev runs: `PROTOBASE_REALTIME_BINARY` when it is set, unchecked;
32
+ * otherwise the pinned release's asset for this machine from the cache, its sha256 checked on every call, downloaded
33
+ * from the release's tag on first use or when the cached file no longer matches. A download is written to a file of
34
+ * its own, checked, made executable and only then renamed into place, so runs side by side or one cut off never leave
35
+ * a partial binary in the cache.
36
+ */
37
+ const realtimeBinary = async ({ env = process.env, release = realtimeRelease, cacheDir, platform = process.platform, arch = process.arch } = {}) => {
38
+ const own = env[realtimeBinaryVariable];
39
+ if (own) return path.resolve(own);
40
+ const asset = realtimeAsset(platform, arch);
41
+ const expected = asset && release.sha256[asset];
42
+ if (!asset || !expected) throw new Error(`Protobase Realtime ${release.version} has no build for ${platform}-${arch}: set ${realtimeBinaryVariable} to a binary of your own, or set realtime.relay.url to a running relay`);
43
+ const versionDir = path.join(cacheDir ?? path.join(userCacheDir(env, platform), "protobase", "realtime"), release.version);
44
+ const file = path.join(versionDir, asset);
45
+ const cached = await readCached(file);
46
+ if (cached && sha256(cached) === expected) return file;
47
+ if (cached) await rm(file, { force: true });
48
+ const url = `${env["PROTOBASE_REALTIME_DOWNLOAD_URL"] || "https://github.com/PrototeamHQ/protobase-realtime/releases/download"}/v${release.version}/${asset}`;
49
+ const bytes = await download(url);
50
+ const actual = sha256(bytes);
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
+ await mkdir(versionDir, { recursive: true });
53
+ const partial = `${file}.${randomBytes(6).toString("hex")}.partial`;
54
+ await writeFile(partial, bytes);
55
+ await chmod(partial, 493);
56
+ await rename(partial, file);
57
+ return file;
58
+ };
59
+ //#endregion
60
+ export { realtimeBinary, realtimeBinaryVariable, realtimeDownloadVariable };
@@ -0,0 +1,13 @@
1
+ //#region src/dev/realtime-release.json
2
+ var realtime_release_default = {
3
+ version: "0.1.0",
4
+ sha256: {
5
+ "protobase-realtime-linux-amd64": "9222d79cf9b1ad222a7580b4cb40fcd9b47ba8bdd4c6dc6b301eee5c57c73a1f",
6
+ "protobase-realtime-linux-arm64": "417801feaffd70849122fa2de59726f02afb78ce75af71bb21856b8dedca9c83",
7
+ "protobase-realtime-darwin-amd64": "811aed0f1f17623a4b900c5cdc2948e4f23343161f770e13836a2800f48ee793",
8
+ "protobase-realtime-darwin-arm64": "70bacaef85cd6b554556a29e7ca0710ced96036083c7b00da9b064ae94198ae0",
9
+ "protobase-realtime-windows-amd64.exe": "93ecd3fc44ca00b19cd5abf86a0d48da2f76436acf844e86c82f76f05b112cfc"
10
+ }
11
+ };
12
+ //#endregion
13
+ export { realtime_release_default as default };
@@ -0,0 +1,32 @@
1
+ import realtime_release_default from "./realtime-release.js";
2
+ //#region src/dev/realtime-release.ts
3
+ const realtimeRelease = realtime_release_default;
4
+ /** Where the releases' assets are, `<base>/v<version>/<asset>`; `PROTOBASE_REALTIME_DOWNLOAD_URL` replaces it, such as with a mirror. */
5
+ const realtimeDownloadBase = "https://github.com/PrototeamHQ/protobase-realtime/releases/download";
6
+ const goos = {
7
+ linux: "linux",
8
+ darwin: "darwin",
9
+ win32: "windows"
10
+ };
11
+ const goarch = {
12
+ x64: "amd64",
13
+ arm64: "arm64"
14
+ };
15
+ /** The asset of every machine the release must have a build for. */
16
+ const realtimeAssets = [
17
+ "protobase-realtime-linux-amd64",
18
+ "protobase-realtime-linux-arm64",
19
+ "protobase-realtime-darwin-amd64",
20
+ "protobase-realtime-darwin-arm64",
21
+ "protobase-realtime-windows-amd64.exe"
22
+ ];
23
+ /** The asset for `platform` and `arch`, such as `protobase-realtime-linux-amd64`; undefined for a machine the release has no build for. */
24
+ const realtimeAsset = (platform, arch) => {
25
+ const os = goos[platform];
26
+ const cpu = goarch[arch];
27
+ if (!os || !cpu) return;
28
+ const asset = `protobase-realtime-${os}-${cpu}${os === "windows" ? ".exe" : ""}`;
29
+ return realtimeAssets.includes(asset) ? asset : void 0;
30
+ };
31
+ //#endregion
32
+ export { realtimeAsset, realtimeAssets, realtimeDownloadBase, realtimeRelease };
@@ -2,9 +2,9 @@ import { devHost } from "./loopback.js";
2
2
  import path from "node:path";
3
3
  import { mkdtemp, rm, writeFile } from "node:fs/promises";
4
4
  import { createServer } from "node:net";
5
+ import { tmpdir } from "node:os";
5
6
  import { spawn } from "node:child_process";
6
7
  import { once } from "node:events";
7
- import { tmpdir } from "node:os";
8
8
  //#region src/dev/relay-process.ts
9
9
  /** The address of a relay on the loopback's `port`. */
10
10
  const relayUrl = (port) => `http://${devHost}:${port}`;
@@ -29,8 +29,8 @@ const startRelay = async (binary, port, entry, onExit) => {
29
29
  await writeFile(appsFile, JSON.stringify({ apps: [entry] }), { mode: 384 });
30
30
  const child = spawn(binary, [], {
31
31
  env: {
32
- RELAY_APPS_FILE: appsFile,
33
- RELAY_ADDR: `${devHost}:${port}`
32
+ PROTOBASE_REALTIME_APPS_FILE: appsFile,
33
+ PROTOBASE_REALTIME_ADDR: `${devHost}:${port}`
34
34
  },
35
35
  stdio: [
36
36
  "ignore",
@@ -0,0 +1,11 @@
1
+ import path from "node:path";
2
+ import { homedir } from "node:os";
3
+ //#region src/dev/user-cache-dir.ts
4
+ /** The user's cache folder by the platform's convention: XDG_CACHE_HOME or ~/.cache on Linux, ~/Library/Caches on macOS, LOCALAPPDATA on Windows. */
5
+ const userCacheDir = (env = process.env, platform = process.platform, home = homedir()) => {
6
+ if (platform === "darwin") return path.join(home, "Library", "Caches");
7
+ if (platform === "win32") return env.LOCALAPPDATA || path.join(home, "AppData", "Local");
8
+ return env.XDG_CACHE_HOME && path.isAbsolute(env.XDG_CACHE_HOME) ? env.XDG_CACHE_HOME : path.join(home, ".cache");
9
+ };
10
+ //#endregion
11
+ export { userCacheDir };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.127.2",
3
+ "version": "0.127.4",
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.127.2",
47
- "@protobase/layout": "0.127.2",
48
- "@protobase/query": "0.127.2",
49
- "@protobase/schema": "0.127.2",
50
- "@protobase/server": "0.127.2",
51
- "@protobase/ui": "0.127.2",
52
- "@protobase/workflows": "0.127.2",
46
+ "@protobase/config": "0.127.4",
47
+ "@protobase/layout": "0.127.4",
48
+ "@protobase/query": "0.127.4",
49
+ "@protobase/schema": "0.127.4",
50
+ "@protobase/server": "0.127.4",
51
+ "@protobase/ui": "0.127.4",
52
+ "@protobase/workflows": "0.127.4",
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",
@@ -17,7 +17,7 @@ The changes of each record, comments on it, and pages that refresh as records ch
17
17
  - [Change stream](../reference/live.md#the-stream): Apps follow record changes over a stream that catches up after a reconnect.
18
18
  - [Polling, then a socket](../reference/live.md#polling-then-a-socket): Apps and Node scripts poll for changes first and switch to a WebSocket after 30 seconds, or at once, falling back to polling while the socket is down.
19
19
  - [Presence](../reference/channels.md#presence) (beta): Apps see who else has a record open and what each of them tracks, such as online or away, for whoever may read the record.
20
- - [Realtime relay](../reference/realtime-relay.md) (in development): Apps hand their realtime connections to a relay, so they and their database can sleep while people stay connected: the app issues connect tickets for signed-in people and visitors, keeps the relay's channel members in step with its members records, tells each channel's members of every change, and closes a session's sockets when it signs out or expires. `protobase dev` runs a relay for the app by itself. An app on a platform that runs the relay, Protobase Realtime, picks up its address and keys from PROTOBASE_REALTIME_URL, PROTOBASE_REALTIME_APP, PROTOBASE_REALTIME_API_KEY, PROTOBASE_REALTIME_TICKET_KEY and PROTOBASE_REALTIME_PRESENCE_KEY; a value in the config wins. `protobase build` writes the app's events and presence for the relay's apps file into the bundle's manifest, and the platform's PROTOBASE_REALTIME_ENABLED switch, true or false, says when it moves the app, an app without realtime.relay too: its conversation pages with members become its channels, whose members Protobase keeps in an indexed table of its own.
20
+ - [Realtime relay](../reference/realtime-relay.md) (in development): Apps hand their realtime connections to a relay, so they and their database can sleep while people stay connected: the app issues connect tickets for signed-in people and visitors, keeps the relay's channel members in step with its members records, tells each channel's members of every change, and closes a session's sockets when it signs out or expires. `protobase dev` runs a relay for the app by itself, downloading Protobase Realtime from its GitHub release on first use. An app on a platform that runs the relay, Protobase Realtime, picks up its address and keys from PROTOBASE_REALTIME_URL, PROTOBASE_REALTIME_APP, PROTOBASE_REALTIME_API_KEY, PROTOBASE_REALTIME_TICKET_KEY and PROTOBASE_REALTIME_PRESENCE_KEY; a value in the config wins. `protobase build` writes the app's events and presence for the relay's apps file into the bundle's manifest, and the platform's PROTOBASE_REALTIME_ENABLED switch, true or false, says when it moves the app, an app without realtime.relay too: its conversation pages with members become its channels, whose members Protobase keeps in an indexed table of its own.
21
21
  - [Relay presence](../reference/realtime-relay.md#presence) (in development): The relay reports who comes online, goes away and goes offline; the app keeps it in a resource of its own, raises that resource's events, so workflows can act when someone goes offline, and tells the people who share a conversation with them, whose sidebar and members page show them online, away or offline.
22
22
  - [Relay in pages](../reference/realtime-relay.md#pages) (in development): Pages follow the relay on one socket: open views stay current from its notices and read again once after a reconnect, conversations show who types, sidebar groups say "typing…" and count unread messages without reading per message, also of a conversation the person was just added to, all by configuration; `client.relay` gives the same from code.
23
23
  - [Relay client events](../reference/realtime-relay.md#client-events) (in development): Each channel resource declares in the config the events its clients may send each other, such as typing, with a schema, a size and a rate.
@@ -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 from `@protobase/realtime`, the project's install or else the CLI's, for the app, gives the app its address and keys, and stops it with the dev server (see [Local development](realtime-relay.md#local-development)).
205
+ - **Realtime relay:** with [`realtime.relay`](realtime-relay.md) and no `url`, it runs the relay for the app, Protobase Realtime downloaded from its GitHub 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.
@@ -489,6 +489,7 @@ Serves the API of a bundle from `protobase build` and owns the process around it
489
489
  | `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 |
490
490
  | `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 |
491
491
  | `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 |
492
+ | `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 its GitHub releases |
492
493
  | `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 |
493
494
  | `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)) |
494
495
  | `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` |
@@ -75,13 +75,9 @@ export default defineConfig({
75
75
 
76
76
  ## Local development
77
77
 
78
- [`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 no second command. Add the relay's npm package to the project once:
78
+ [`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 GitHub 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.
79
79
 
80
- ```sh
81
- npm install --save-dev @protobase/realtime
82
- ```
83
-
84
- <gap>`protobase dev` cannot run the relay without the project installing `@protobase/realtime` because the CLI does not depend on it until the package is published.</gap>
80
+ <gap>`protobase dev` cannot download Realtime on Windows on Arm because a release build for it is not implemented.</gap>
85
81
 
86
82
  It starts the relay on the first load of a config with `realtime.relay`, an edit that adds it included, on a free port of `127.0.0.1`, serving this one app with the dev server's origin, and gives the app its address. The keys, the presence key included, are the config's when it sets them, and otherwise made anew for each `protobase dev`. An edit that changes the app's id or keys starts it again, one that removes `realtime.relay` or sets a `url` stops it, and it stops with `dev`. Its own messages, such as an apps file it refuses, show in the terminal. With a `url`, the app uses that relay and `dev` starts none. `dev` reads [the platform's variables](#from-the-platform) for neither: the app's id comes from the config.
87
83
 
@@ -1,30 +0,0 @@
1
- import { createRequire } from "node:module";
2
- import path from "node:path";
3
- import { fileURLToPath, pathToFileURL } from "node:url";
4
- //#region src/dev/relay-binary.ts
5
- const relayPackage = "@protobase/realtime";
6
- const cliDir = fileURLToPath(new URL("../..", import.meta.url));
7
- const resolveFrom = (dir) => {
8
- try {
9
- return createRequire(path.join(dir, "package.json")).resolve(relayPackage);
10
- } catch (error) {
11
- if (error.code === "MODULE_NOT_FOUND") return;
12
- throw error;
13
- }
14
- };
15
- /** The entry of the relay's npm package: the project's own install first, then the CLI's. */
16
- const relayPackageEntry = (projectDir, ownDir = cliDir) => {
17
- const entry = resolveFrom(projectDir) ?? resolveFrom(ownDir);
18
- if (!entry) throw new Error(`realtime.relay has no url, so protobase dev runs a relay of its own from ${relayPackage}, which is not installed: add it to the project's devDependencies, or set realtime.relay.url to a running relay`);
19
- return entry;
20
- };
21
- /** The path of the relay binary for this machine, as the package's `binaryPath()` finds it. */
22
- const relayBinary = async (projectDir, ownDir = cliDir) => {
23
- const { binaryPath } = await import(
24
- /* @vite-ignore */
25
- pathToFileURL(relayPackageEntry(projectDir, ownDir)).href
26
- );
27
- return binaryPath();
28
- };
29
- //#endregion
30
- export { relayBinary, relayPackage, relayPackageEntry };