@protobase/cli 0.124.0 → 0.124.2

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.124.0";
2
+ var version = "0.124.2";
3
3
  //#endregion
4
4
  export { version };
@@ -31,11 +31,12 @@ const withDevRelay = async (config, projectDir, devUrl, views) => {
31
31
  return config;
32
32
  }
33
33
  const keys = devKeys();
34
- const options = {
34
+ const options = checkRelayOptions({
35
35
  ...relay,
36
+ url: devUrl,
36
37
  apiKey: relay.apiKey || keys.apiKey,
37
38
  ticketKey: relay.ticketKey || keys.ticketKey
38
- };
39
+ });
39
40
  const entry = JSON.stringify({
40
41
  ...relayAppEntry(options, {
41
42
  url: devUrl,
@@ -46,10 +47,6 @@ const withDevRelay = async (config, projectDir, devUrl, views) => {
46
47
  if (store.__protobaseDevRelay?.entry !== entry) {
47
48
  await stopDevRelay();
48
49
  const port = await freePort();
49
- checkRelayOptions({
50
- ...options,
51
- url: relayUrl(port)
52
- });
53
50
  store.__protobaseDevRelay = {
54
51
  entry,
55
52
  url: relayUrl(port),
@@ -1,7 +1,7 @@
1
1
  //#region src/relay/register.ts
2
2
  const registerRelay = (program) => {
3
- program.command("relay").description("The realtime relay the app hands its connections to (realtime.relay)").command("app").description("Print the app's entry for the relay's apps file, from realtime.relay, url and the views").action(async () => {
4
- const [{ checkRelayOptions, configExports }, { loadSourceConfig }, { projectResources }, { loadNearestEnvFile }, { relayAppEntry }] = await Promise.all([
3
+ program.command("relay").description("The realtime relay the app hands its connections to (realtime.relay)").command("app").description("Print the app's entry for the relay's apps file, from realtime.relay or PROTOBASE_RELAY_*, url and the views").action(async () => {
4
+ const [{ configExports, relaySettings }, { loadSourceConfig }, { projectResources }, { loadNearestEnvFile }, { relayAppEntry }] = await Promise.all([
5
5
  import("@protobase/server"),
6
6
  import("../config/source-config.js"),
7
7
  import("../config/project-parts.js"),
@@ -13,7 +13,7 @@ const registerRelay = (program) => {
13
13
  if (!config.realtime?.relay) throw new Error("The config has no realtime.relay");
14
14
  const url = config.url ?? process.env.PROTOBASE_URL;
15
15
  const views = configExports(await projectResources(config)).views.map((view) => view.toModel());
16
- process.stdout.write(`${JSON.stringify(relayAppEntry(checkRelayOptions(config.realtime.relay), {
16
+ process.stdout.write(`${JSON.stringify(relayAppEntry(relaySettings(config.realtime.relay, process.env), {
17
17
  url,
18
18
  apiPath: config.apiPath,
19
19
  views
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.124.0",
3
+ "version": "0.124.2",
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.124.0",
47
- "@protobase/layout": "0.124.0",
48
- "@protobase/query": "0.124.0",
49
- "@protobase/schema": "0.124.0",
50
- "@protobase/server": "0.124.0",
51
- "@protobase/ui": "0.124.0",
52
- "@protobase/workflows": "0.124.0",
46
+ "@protobase/config": "0.124.2",
47
+ "@protobase/layout": "0.124.2",
48
+ "@protobase/query": "0.124.2",
49
+ "@protobase/schema": "0.124.2",
50
+ "@protobase/server": "0.124.2",
51
+ "@protobase/ui": "0.124.2",
52
+ "@protobase/workflows": "0.124.2",
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",
@@ -6,6 +6,7 @@ Uploaded files and images, where they are kept and how they are served.
6
6
 
7
7
  - [File fields](../reference/files.md#what-the-column-holds): A text column holds an uploaded file, with limits on type and size.
8
8
  - [File uploads in forms](../reference/files.md#in-forms): Forms upload a dropped or chosen file at once with a progress bar, and replace or remove it; tables show its name and a thumbnail.
9
+ - [Camera capture](../reference/files.md#camera-capture): File fields can open the camera directly on phones and tablets with `.capture()`, so a photo is taken and attached in one step.
9
10
  - [File storage](../reference/files.md#providers): Files are kept on disk, or in a bucket of your own.
10
11
  - [S3-compatible buckets](../reference/files.md#s3-compatible-buckets) (beta): Files are kept in any bucket that speaks the S3 API, when the app runs on Bun.
11
12
  - [Files from a seed](../reference/files.md#writing-files-from-a-seed): A seed or another script writes files into the app's providers, read from its config and environment as the server reads them.
@@ -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.
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 picks up its address and keys from PROTOBASE_RELAY_URL, PROTOBASE_RELAY_APP, PROTOBASE_RELAY_API_KEY and PROTOBASE_RELAY_TICKET_KEY; a value in the config wins.
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.
@@ -483,6 +483,7 @@ Serves the API of a bundle from `protobase build` and owns the process around it
483
483
  | `PROTOBASE_RUNTIME_URL` | the endpoint behind the top bar's [runtime update button](versioning.md#runtime-updates), such as a hosting platform's; without it there is no button |
484
484
  | `PROTOBASE_MAIL_CHECK_URL` | the hosting platform's service that [checks a From address](email.md#checking-a-from-address), signed with a key derived from `PROTOBASE_SECRET`; without it the account page says addresses cannot be checked |
485
485
  | `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 |
486
+ | `PROTOBASE_RELAY_URL`, `PROTOBASE_RELAY_APP`, `PROTOBASE_RELAY_API_KEY`, `PROTOBASE_RELAY_TICKET_KEY` | the address, the app's id and its API and ticket keys of the [realtime relay](realtime-relay.md#from-the-platform), each where the config's `realtime.relay` leaves it out; without `realtime.relay` the relay stays off |
486
487
  | `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 |
487
488
  | `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)) |
488
489
  | `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` |
@@ -678,7 +679,7 @@ Recounts a [time rollup](data-config.md#keeping-it-up-to-date)'s buckets from th
678
679
  protobase relay app
679
680
  ```
680
681
 
681
- Prints the app's entry for the apps file of the [realtime relay](realtime-relay.md), as JSON: its `id`, `api_keys` and `ticket_keys` from `realtime.relay`, and in `origins` the origin of the app's `url` (or `PROTOBASE_URL`); in `client_events` each channel resource's [client events](realtime-relay.md#client-events), with `typing` on those whose conversation page types; with [presence](realtime-relay.md#presence), `presence` with the app's presence endpoint at that `url`, the presence key and a `grace_seconds` of 30. Add the relay's limits and options to it there. It reads `protobase.config.ts` with `command: 'tool'` and the `.env` nearest the current directory.
682
+ Prints the app's entry for the apps file of the [realtime relay](realtime-relay.md), as JSON: its `id`, `api_keys` and `ticket_keys` from `realtime.relay`, or else `PROTOBASE_RELAY_APP`, `PROTOBASE_RELAY_API_KEY` and `PROTOBASE_RELAY_TICKET_KEY`, and in `origins` the origin of the app's `url` (or `PROTOBASE_URL`); in `client_events` each channel resource's [client events](realtime-relay.md#client-events), with `typing` on those whose conversation page types; with [presence](realtime-relay.md#presence), `presence` with the app's presence endpoint at that `url`, the presence key and a `grace_seconds` of 30. Add the relay's limits and options to it there. It reads `protobase.config.ts` with `command: 'tool'` and the `.env` nearest the current directory.
682
683
 
683
684
  ## `auth migration`
684
685
 
@@ -56,6 +56,7 @@ export const bikes = resource('bikes')
56
56
  | `.placeholder('photo_placeholder')` | Each image's ThumbHash in that text field, drawn while the image loads, see [Image variants and placeholders](#image-variants-and-placeholders). |
57
57
  | `.variants({ card: { … } }, { original? })` | Resized copies of each image stored beside it, see [Image variants and placeholders](#image-variants-and-placeholders). |
58
58
  | `.externalUrls()` | Also takes an https URL of a file elsewhere instead of an upload, see [External URLs](#external-urls). |
59
+ | `.capture()`, `.capture('user')` | Opens the rear camera, or the front one with `'user'`, on phones and tablets, and takes only images, see [Camera capture](#camera-capture). |
59
60
 
60
61
  A file field cannot be filterable, sortable, aliased, searched, sensitive, or the key, tenant, owner or soft delete field. [`protobase doctor`](cli.md#doctor) checks that its column is a text type.
61
62
 
@@ -174,6 +175,17 @@ A write takes only a ticket, `null` to clear the field, or the stored `uri` unch
174
175
 
175
176
  In the admin app's create and edit forms, a file field takes a dropped or chosen file, limited to the field's `.accept()` types, and uploads it at once with a progress bar; Save then stores it with the record. A stored file shows its thumbnail or an icon, its name linking to the file, its type and size, and the type it was sent as when the server corrected it. Replace picks another file, and Remove, for an optional field, clears it. Tables show the file's name, beside a small thumbnail for an image.
176
177
 
178
+ ### Camera capture
179
+
180
+ A field with `.capture()` opens the camera directly on phones and tablets, so a photo is taken and attached in one step, such as a mechanic photographing a meter. The rear camera opens by default, and `.capture('user')` opens the front one.
181
+
182
+ ```ts
183
+ meter_photo: f.file().capture(),
184
+ selfie: f.file().capture('user').optional(),
185
+ ```
186
+
187
+ The field takes only images: the image types of its `.accept()`, or any image when it names none, and an `.accept()` after it that names another type is an error. On a phone or tablet the form offers Take a photo, which opens the camera, and Choose a photo, which opens the phone's own chooser for a photo taken before; a stored photo offers Retake beside Replace. A desktop browser has no camera to open, so the field picks or takes a dropped image file.
188
+
177
189
  ### How the type is decided
178
190
 
179
191
  An upload carries three hints: what the **content** is (C, from its magic bytes), what the **name's extension** says (E), and what the **client declared** (H, the request's or the file part's `Content-Type`; `application/octet-stream` counts as none).
@@ -47,7 +47,26 @@ export default defineConfig(({ env }) => ({
47
47
 
48
48
  The relay needs the app's own [sign-in](auth.md), whose sessions its tickets name, with its store in the app's own database, as the `auth` config puts it: an auth store in another database is refused. A members resource's changes must be captured, so declare [`.live()`](live.md) on it; the relay hears of the changes of every resource whose changes are captured, such as a live one, that is a channel resource or has a relation field to one. [`protobase migration`](cli.md#migration) writes the trigger that ends a deleted session's sockets, in the `relay` schema, after the auth store's steps when the same file writes them, so a new app's first migration sets up both; the server checks it at start.
49
49
 
50
- [`protobase relay app`](cli.md#relay-app) prints the app's entry for the relay's apps file, from this config and the app's `url`.
50
+ [`protobase relay app`](cli.md#relay-app) prints the app's entry for the relay's apps file, from this config, these variables and the app's `url`.
51
+
52
+ ### From the platform
53
+
54
+ An app on a platform that runs the relay picks up its address and keys from the environment, so its config names only its channels:
55
+
56
+ | Variable | Default of |
57
+ | --- | --- |
58
+ | `PROTOBASE_RELAY_URL` | `url` |
59
+ | `PROTOBASE_RELAY_APP` | `app` |
60
+ | `PROTOBASE_RELAY_API_KEY` | `apiKey` |
61
+ | `PROTOBASE_RELAY_TICKET_KEY` | `ticketKey` |
62
+
63
+ Each is a default on its own: a value in the config wins, and a key that neither sets stops the server at start, naming the key and its variable. The relay stays off without `realtime.relay` in the config, however many of these are set: the app turns it on by declaring its channels.
64
+
65
+ ```ts
66
+ export default defineConfig({
67
+ realtime: { relay: { channels: { conversations: { members: { resource: 'conversation_members', channel: 'conversation_id', user: 'user_id' } } } } },
68
+ })
69
+ ```
51
70
 
52
71
  ## Local development
53
72
 
@@ -59,7 +78,7 @@ npm install --save-dev @protobase/realtime
59
78
 
60
79
  <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>
61
80
 
62
- 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 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.
81
+ 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 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.
63
82
 
64
83
  ## Tickets
65
84