@protobase/cli 0.133.11 → 0.134.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.133.11";
2
+ var version = "0.134.0";
3
3
  //#endregion
4
4
  export { version };
@@ -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
@@ -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 relayEnded = (code) => {
20
- delete store.__protobaseDevRelay;
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
- if (store.__protobaseDevRelay?.entry !== entry) {
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: store.__protobaseDevRelay.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 = async () => {
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
- await writeFile(partial, bytes);
55
- await chmod(partial, 493);
56
- await rename(partial, file);
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
@@ -1,12 +1,12 @@
1
1
  //#region src/dev/realtime-release.json
2
2
  var realtime_release_default = {
3
- version: "0.1.0",
3
+ version: "0.2.0",
4
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"
5
+ "protobase-realtime-linux-amd64": "df30c0e6600744f36d5a6f5ffc56a68318a2fe7eb53dc8bcb86a47fc83430fc2",
6
+ "protobase-realtime-linux-arm64": "6d7b27f49ede3086a0f1077b0ce21c14e5c9fe7182427ef607fe592b092baab0",
7
+ "protobase-realtime-darwin-amd64": "43f892cd10ec2873c98448cc4bdfca28cf24d7d84cd9a023750094eb2d12e60b",
8
+ "protobase-realtime-darwin-arm64": "8ccca3f8724247da157bc1f951502611d6a290d29f02902d86c2c54771df97ef",
9
+ "protobase-realtime-windows-amd64.exe": "c1dd4ffba08b8fd3db27a35e652c0a5650f07e48a218cbeae1472f6db7e7e137"
10
10
  }
11
11
  };
12
12
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.133.11",
3
+ "version": "0.134.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": {
@@ -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.11",
47
- "@protobase/layout": "0.133.11",
48
- "@protobase/query": "0.133.11",
49
- "@protobase/schema": "0.133.11",
50
- "@protobase/server": "0.133.11",
51
- "@protobase/ui": "0.133.11",
52
- "@protobase/workflows": "0.133.11",
46
+ "@protobase/config": "0.134.0",
47
+ "@protobase/layout": "0.134.0",
48
+ "@protobase/query": "0.134.0",
49
+ "@protobase/schema": "0.134.0",
50
+ "@protobase/server": "0.134.0",
51
+ "@protobase/ui": "0.134.0",
52
+ "@protobase/workflows": "0.134.0",
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",
@@ -32,7 +32,7 @@ Develop, build and run an app, on servers, in containers and on phones.
32
32
  - [Self-hosted image](../guides/deploy.md#a-self-hosted-image): One image with the app inside that serves, migrates and creates the first admin.
33
33
  - [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.
34
34
  - [Deploy checks in CI](../guides/deploy.md#check-a-change-before-it-merges): One step in an app's GitHub workflow runs the checks a Protobase Cloud deploy runs, the server's startup checks included, on a fresh Postgres of its own, so a change that would not deploy or start fails before it merges.
35
- - [The version before in CI](../guides/deploy.md#test-the-version-that-serves-on-the-new-schema) (beta): A workflow to copy into an app runs the tests of the version that serves now on a database with a branch's migrations applied, so a migration that takes what that version reads fails before it deploys.
35
+ - [The version before in CI](../guides/deploy.md#test-the-version-that-serves-on-the-new-schema) (coming soon): A workflow to copy into an app runs the tests of the version that serves now on a database with a branch's migrations applied, so a migration that takes what that version reads fails before it deploys.
36
36
  - [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. Your app shows its own home-screen icon on iOS and Android, generated from one image you name in your config. It can open on a splash screen of its own, an image on a colour, in light and dark mode.
37
37
  - [Files from the phone](../guides/mobile-app.md#files-from-the-phone) (beta): In the iOS and Android app, Import and file fields open the phone's file picker, offering Excel, CSV and JSON files from the device and its cloud drives.
38
38
  - [Mobile releases](../reference/cli.md#mobile-releases) (in development): The server offers the mobile app a newer copy of its files, signed, and any host that serves bundles can offer the same from the bundle's files without running its config.
@@ -13,7 +13,7 @@ The changes of each record, comments on it, and pages that refresh as records ch
13
13
  - [Mentions](../reference/comments.md#mentions): Mentioning a colleague in a comment sends them an email with a link to the record.
14
14
  - [Comment moderation](../reference/comments.md#moderation): Admins find and delete comments across the app.
15
15
  - [Live updates](../reference/live.md#what-a-page-hears): Open lists and record pages refresh within seconds when a record changes, including changes made outside the API.
16
- - [Live tokens](../reference/live.md#live-tokens) (in development): A list or record read asked for with `Prefer: live` also returns an encrypted token that holds what the reader read and may read, with the read's snapshot, bound to their session. Subscribing with it is coming soon.
16
+ - [Live tokens](../reference/live.md#live-tokens) (in development): A list or record read asked for with `Prefer: live` also returns an encrypted token that holds what the reader read and may read, with the read's snapshot, bound to their session. In an app with the relay, pages subscribe with it on the relay's one socket and poll where the relay cannot keep a resource live.
17
17
  - [Refreshing access](../reference/live.md#refreshing-access) (in development): An API function tells a person's open pages to read again once their access changed, so they get new tokens.
18
18
  - [Live views](../reference/live.md#resources-backed-by-a-view) (experimental): A resource backed by a view updates live when the tables it reads change.
19
19
  - [Change stream](../reference/live.md#the-stream): Apps follow record changes over a stream that catches up after a reconnect.
@@ -50,8 +50,8 @@ It refuses as well on a database ahead of it by a migration that is not additive
50
50
 
51
51
  ### Test the version that serves on the new schema
52
52
 
53
- :::caution[Beta]
54
- <gap>The workflow cannot find the version that serves by itself because recording the app's deployed release is not implemented.</gap>
53
+ :::caution[Coming soon]
54
+ <gap>An app cannot take up this workflow as a file because shipping it in an example or a Protobase file, tested, is not implemented.</gap> <gap>The workflow cannot find the version that serves by itself because recording the app's deployed release is not implemented.</gap>
55
55
  :::
56
56
 
57
57
  While a deploy migrates, the version that serves now keeps running on the new schema until the new one takes over. This workflow, as `.github/workflows/older-code.yml`, applies a branch's migrations to an empty Postgres 18 and runs the tests of the version that serves now, checked out with its own packages, against that database through `DATABASE_URL`. A failing test names what the version before needs and the branch's migrations take, such as a column they drop. It checks what the app's tests read from the database, so it proves as much as those tests open. Run it from the Actions tab, giving the tag, branch or commit that serves; add `pull_request:` under `on:` to run it on every pull request, against the branch it merges into. A migration marked `-- protobase:breaks-older-code` is expected to fail it, since the version before refuses to start on it, but it does so only through a test that starts that version's server or reads what the migration changed: tests that do neither still pass.
@@ -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 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)).
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 its GitHub releases |
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` |
@@ -33,7 +33,7 @@ It is live data, not multiplayer editing: two people editing the same record sti
33
33
 
34
34
  ## The stream
35
35
 
36
- `GET /api/live` answers a `text/event-stream` to anyone who may read a live resource, a visitor of the anonymous role too. Each event's data is JSON with a `cursor`:
36
+ An app with the [relay](realtime-relay.md) serves no stream: its pages hear the same [over the relay](#over-the-relay). `GET /api/live` answers a `text/event-stream` to anyone who may read a live resource, a visitor of the anonymous role too. Each event's data is JSON with a `cursor`:
37
37
 
38
38
  | `type` | |
39
39
  | --- | --- |
@@ -47,7 +47,7 @@ Connecting again with `?after=<cursor>` catches up on what was missed while disc
47
47
  ## Live tokens
48
48
 
49
49
  :::caution[In development]
50
- Reads give live tokens, but nothing takes them yet: subscribing with a token is coming soon.
50
+ Live tokens and the pages that subscribe with them over the relay are in development.
51
51
  :::
52
52
 
53
53
  A list or record read of a live resource gives a live token on request: `GET /api/v1/<resource>`, `GET /api/v1/<resource>/<key>`, the list under a record and `:search` take RFC 7240 `Prefer: live`, or `?live=1` where a page cannot set headers. The answer then has `Preference-Applied: live` and the token in `Protobase-Live`. Without the request the server resolves and encrypts nothing. These reads answer `Vary: Prefer`, so a cache keeps the two answers apart, and the API's CORS allows `Prefer` and exposes `Protobase-Live` and `Preference-Applied`.
@@ -74,10 +74,20 @@ The server gives no token, and no `Preference-Applied`, when it cannot write the
74
74
  ### Refreshing access
75
75
 
76
76
  :::caution[In development]
77
- Pages read again on a refresh; the tokens they get are not taken by anything yet.
77
+ Pages read again on a refresh. Only pages of an app with the relay join with the new tokens; under `protobase dev`, and in an app without the relay, nothing takes them yet.
78
78
  :::
79
79
 
80
- `live.refresh({ user })`, on the context of an [API function](../guides/api-functions.md), also one served for supabase-js, and of a function a webhook subscription calls, tells the open pages of the user with that id to read everything they show again, which gives them new tokens for their access as it is now. Call it once a change of their roles or memberships has committed. It writes a notice in its own transaction, so a page that reconnects with `?after=` still gets it. In an app without a live resource or calls it does nothing.
80
+ `live.refresh({ user })`, on the context of an [API function](../guides/api-functions.md), also one served for supabase-js, and of a function a webhook subscription calls, tells the open pages of the user with that id to read everything they show again, which gives them new tokens for their access as it is now. Call it once a change of their roles or memberships has committed. It writes a notice in its own transaction, so a page that reconnects with `?after=` still gets it; with the relay, it publishes `refresh` to the user on the relay's `people` channel, and the page also reads again each time its socket connects again. In an app without a live resource or calls it does nothing.
81
+
82
+ ### Over the relay
83
+
84
+ In an app with the relay, each page follows its live resources on the relay's one socket, with the socket its other relay features use. [`client.relay.live({ resources, polled?, onChanges, onResync })`](client.md) of `@protobase/client` does the same from code, sharing one socket however many callers follow it. For each resource it reads a token of every record the caller may read, `GET /api/v1/<resource>?limit=1` with `Prefer: live`, and joins the relay's live query `live:<resource>` with it. It then hears the changes as `onChanges` does above, and reads the resource again once, since what the page read came before the token.
85
+
86
+ - Each change carries a cursor. When the token expires, or the socket connects again, it joins with a fresh token after the last cursor, so nothing in between is missed.
87
+ - When the relay's changes service no longer has every change since the cursor, the live query starts again from a new read, and the resource is read again.
88
+ - The relay's `people` channel carries `refresh`, which reads everything again with new tokens, and `rings`, for the calls that ring the person.
89
+
90
+ A resource the relay cannot keep live is read again every 30 seconds instead, and whenever the window gets the focus again, as every query is. That happens when the read gives no token, when the relay has no changes service or lost it, and while the socket is down. Polling stops at the resource's next change. A token read that got no answer is tried again at each poll, until the join succeeds. A resource live from others, given in `polled`, is always polled this way. <gap>A resource live from others (`.live({ reads })`) cannot update at once over the relay because live queries of the resources it reads are not implemented.</gap> <gap>Pages under `protobase dev` cannot take live updates over its relay, and poll instead, because running a change stream for that relay is not implemented.</gap>
81
91
 
82
92
  ## Resources backed by a view
83
93
 
@@ -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 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.
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
 
@@ -161,7 +161,7 @@ An event's name is 1 to 64 bytes and none of `heartbeat`, `interest`, `presence`
161
161
 
162
162
  With `realtime.relay`, the admin app follows the relay for someone signed in, on one socket per page, and `/meta` names the resources whose changes the relay notices:
163
163
 
164
- - **Live updates:** the lists, records and counts of those resources are read again as the relay notices their changes, new, edited and deleted records alike, instead of through [`/api/live`](live.md), which stays for the other `.live()` resources. While a [conversation page](ui-config.md#conversation-pages) is open, only its own channel's notices read it again; the notices of other channels only move the [unread marks](sidebar.md#typing-and-unread-from-the-relay). After the socket was down, everything shown is read again once.
164
+ - **Live updates:** the lists, records and counts of those resources are read again as the relay notices their changes, new, edited and deleted records alike, and the other `.live()` resources over [live queries](live.md#over-the-relay) on the same socket: an app with the relay serves no `/api/live`. While a [conversation page](ui-config.md#conversation-pages) is open, only its own channel's notices read it again; the notices of other channels only move the [unread marks](sidebar.md#typing-and-unread-from-the-relay). After the socket was down, everything shown is read again once.
165
165
  - **Typing:** a conversation page with `typing` says who else types, above its box and in a thread's box, and tells the others while the reader types, as `typing` events on the record's relay channel. Without the relay, it goes over the record's own [channel](channels.md) instead. A sidebar group with [`typing`](sidebar.md#typing-and-unread-from-the-relay) says "typing…" beside a record someone types in, wherever the reader is.
166
166
  - **Unread:** a sidebar group with [`unread`](sidebar.md#typing-and-unread-from-the-relay) counts each conversation's unread messages once, then adds the relay's notices without reading.
167
167
  - **Presence:** the page tells the relay the person is away while it is hidden and online once it shows; a page that shows again, or a device back online, connects again at once. With [presence](#presence), `/meta` names its resource and fields, never its key, and the sidebar's person marks, the members page and a conversation's members title show who is online, away or offline: the page reads the records of the people it shows, up to 100 in one request, those it shows later as they appear, everyone shown again after the socket was down, and applies each `presence_changed` as it comes, keeping a status only over one that began earlier. The `presence_changed` events reach everyone who shares a channel with the person, whatever their role reads, but the reads go through the reader's role: someone whose record it may not read shows no presence until their next change comes, so grant `presences.read` to the people who see each other. An app's own [`presence` hook](status.md#in-the-app) goes over it.
@@ -192,7 +192,7 @@ client.relay.presence('away')
192
192
 
193
193
  | | |
194
194
  | --- | --- |
195
- | `follow(handlers)` | Hears every notice and event until the returned function is called. The first follower opens the socket and the last closes it. The socket connects with a fresh ticket each time, joins the relay's own topic and every channel the ticket lists, and each channel a `joined` event names, telling `onJoined` once it joined it, and connects again after a pause that grows with each failure, up to 30 seconds; an app that refuses a ticket with a client error, such as for a session that ended, ends it (`ended`), as does a relay that closes it with code 1000. It tries a WebSocket first: when that fails before it opened, or does not open within 2.5 seconds, as on a network that blocks WebSockets, and none opened before, it connects over the relay's server-sent events at once instead, and stays on them until the page loads again. <gap>The relay protobase dev runs cannot take server-sent event connections because pinning a release of it that serves them is not implemented.</gap> |
195
+ | `follow(handlers)` | Hears every notice and event until the returned function is called. The first follower opens the socket and the last closes it. The socket connects with a fresh ticket each time, joins the relay's own topic and every channel the ticket lists, and each channel a `joined` event names, telling `onJoined` once it joined it, and connects again after a pause that grows with each failure, up to 30 seconds; an app that refuses a ticket with a client error, such as for a session that ended, ends it (`ended`), as does a relay that closes it with code 1000. It tries a WebSocket first: when that fails before it opened, or does not open within 2.5 seconds, as on a network that blocks WebSockets, and none opened before, it connects over the relay's server-sent events at once instead, and stays on them until the page loads again. |
196
196
  | `send(channel, event, payload)` | Sends a declared event to the channel's other sockets. Rejects with a `RelayRefusal` and the relay's reason, such as `rate_limited` or `event_not_allowed`, or `not_joined`. |
197
197
  | `direct(to, event, payload)` | Sends a declared direct event to every device of a person who shares a channel with the sender. |
198
198
  | `join(channel)` | Joins a channel the ticket did not list, such as one the person joined since, and again after each reconnect until the returned function is called. The socket stays in the channel until it next connects. |