@protobase/cli 0.132.1 → 0.132.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.132.1";
2
+ var version = "0.132.2";
3
3
  //#endregion
4
4
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.132.1",
3
+ "version": "0.132.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.132.1",
47
- "@protobase/layout": "0.132.1",
48
- "@protobase/query": "0.132.1",
49
- "@protobase/schema": "0.132.1",
50
- "@protobase/server": "0.132.1",
51
- "@protobase/ui": "0.132.1",
52
- "@protobase/workflows": "0.132.1",
46
+ "@protobase/config": "0.132.2",
47
+ "@protobase/layout": "0.132.2",
48
+ "@protobase/query": "0.132.2",
49
+ "@protobase/schema": "0.132.2",
50
+ "@protobase/server": "0.132.2",
51
+ "@protobase/ui": "0.132.2",
52
+ "@protobase/workflows": "0.132.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",
@@ -18,6 +18,7 @@ The changes of each record, comments on it, and pages that refresh as records ch
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
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
+ - [Organization-wide relay channels](../reference/realtime-relay.md#organization-wide-channels) (in development): One channel resource holds channels for the whole organization beside channels for the people they list, such as a chat's public and private channels: a record whose members field is null reaches everyone in its organization, and people who join or leave the organization join or leave its channels on their open sockets.
21
22
  - [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
23
  - [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
24
  - [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.
@@ -40,7 +40,7 @@ export default defineConfig(({ env }) => ({
40
40
  | `app` | The app's id on the relay: 1 to 64 of `a-z`, `0-9`, `_` and `-`. |
41
41
  | `apiKey`, `ticketKey` | One of the app's API keys and one of its ticket keys on the relay, each at least 32 characters. |
42
42
  | `channels` | The channel resources, by name. Each record of one is a channel, `<resource>/<key>`, named as its [record channel](channels.md) is; the resource needs a key of one field. Without `channels`, each resource whose [conversation page](ui-config.md#conversation-pages) has `members` is one, with that field as its members, when its changes are captured, such as with [`.live()`](live.md), and its key is one field; views of one resource whose pages list members in different fields stop the server. |
43
- | `channels.<resource>.members` | Where the channel's members come from: a resource whose records each put one person in one channel, with its relation field to the channel resource (`channel`) and its field of the person's user id (`user`); index both columns, as tickets read by the user and notices by the channel. Or `{ field }`, a JSON field of user ids on the channel record itself, as a conversation page's `members`, neither sensitive nor in `.history({ ignore })`, so its every change reaches the relay: Protobase keeps who is in each channel in its `realtime.members` table, so the app adds no index. Without `members`, the channel is open: a channel of a public record, which tickets list when asked (see [Tickets](#tickets)). |
43
+ | `channels.<resource>.members` | Where the channel's members come from: a resource whose records each put one person in one channel, with its relation field to the channel resource (`channel`) and its field of the person's user id (`user`); index both columns, as tickets read by the user and notices by the channel. Or `{ field }`, a JSON field of user ids on the channel record itself, as a conversation page's `members`, neither sensitive nor in `.history({ ignore })`, so its every change reaches the relay: Protobase keeps who is in each channel in its `realtime.members` table, so the app adds no index. With `organization: 'when-null'` beside `field`, a record whose field is null reaches every member of its tenant's organization instead (see [Organization-wide channels](#organization-wide-channels)). Without `members`, the channel is open: a channel of a public record, which tickets list when asked (see [Tickets](#tickets)). |
44
44
  | `channels.<resource>.mentions` | A field of the records noticed on the channel that lists the user ids they mention, an array or one id, which [notices](#notices) carry. |
45
45
  | `channels.<resource>.events` | The [events](#client-events) the channel's members may send each other, by name, each with its payload's `schema`, its `maxBytes` and the rate one person may send it at, `perSecond` in bursts of `burst`. |
46
46
  | `presence` | Turns on [presence](#presence): the app's own resource it is kept in, its fields of the person's user id (`user`), the status (`status`) and when it began (`at`), and the bearer token of the relay's reports (`key`), at least 32 characters, which defaults to [`PROTOBASE_REALTIME_PRESENCE_KEY`](#from-the-platform). |
@@ -49,6 +49,16 @@ The relay needs the app's own [sign-in](auth.md), whose sessions its tickets nam
49
49
 
50
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
51
 
52
+ ### Organization-wide channels
53
+
54
+ A workspace chat keeps public and private channels in one resource: a public channel's `member_ids` is null, and everyone in the workspace reads it; a private one lists its members.
55
+
56
+ ```ts
57
+ channels: { channels: { members: { field: 'member_ids', organization: 'when-null' } } }
58
+ ```
59
+
60
+ A record whose field is null, in SQL, reaches every member of its [tenant](data-config.md#resource)'s organization, as the auth store's member table holds them; one with a list, an empty one included, reaches only the people it lists, so a private channel never widens. The resource needs `.tenant`, and the app [organizations](auth.md#organizations): the server refuses to start otherwise. Tickets list such a channel for each member of its organization, notices and client events reach them, and a record whose field turns null or turns into a list moves its organization in or out as a list change moves the people it lists. Someone who joins an organization joins its organization-wide channels on the sockets they have open and hears `joined` of each; someone who leaves it, or whose organization or account is deleted, leaves them. [`protobase migration`](cli.md#migration) writes the triggers on the member table that queue a `relay.organization-members` job for each statement that changes who is in an organization, in the `relay` schema, while a channel resource has `organization`, and drops them once none has. <gap>A truncate of the member table cannot move people out of organization-wide channels because following a truncate of it is not implemented.</gap> Index the tenant column for the records whose field is null, such as `create index on channels (organization_id) where member_ids is null`, as tickets and joins read them by organization.
61
+
52
62
  ### From the platform
53
63
 
54
64
  An app on a platform that runs the relay, Protobase Realtime, picks up its address and keys from the environment, so its config names only its channels:
@@ -85,7 +95,7 @@ It starts the relay on the first load of a config with `realtime.relay`, an edit
85
95
 
86
96
  A client connects to the relay with a ticket from `POST /api/relay/ticket`, with `{ "channels": [...] }`, optional, as JSON. The answer is `{ ticket, url, channels, expiresAt }`: the relay's socket address, a ticket that connects once, within a minute, and the channels it lists, which the client joins. Every connection, a reconnect too, takes a new ticket.
87
97
 
88
- - **Signed in:** the ticket names the person and the sign-in session they called with, so a device that connects makes no new session, and lists every channel they are a member of, as the members resources and `realtime.members` hold it, and `people`, which every signed-in person has and [presence](#presence) is published on. A caller without a session of the app, such as an API key or an outside app acting for the user, is refused with `403`; a session that ended with `401`.
98
+ - **Signed in:** the ticket names the person and the sign-in session they called with, so a device that connects makes no new session, and lists every channel they are a member of, as the members resources and `realtime.members` hold it, every [organization-wide](#organization-wide-channels) channel of each organization they are a member of, and `people`, which every signed-in person has and [presence](#presence) is published on. A caller without a session of the app, such as an API key or an outside app acting for the user, is refused with `403`; a session that ended with `401`.
89
99
  - **Visitors:** with an `anonymous` role, a caller without a token gets a ticket of an anonymous session of its own, which receives and never sends.
90
100
  - **Open channels:** both list the channels they ask for in `channels` of resources without `members` whose records are public: the `anonymous` role may read them, as `GET /api/v1/<resource>/<key>` decides it for a visitor. Someone's own access to a record never makes its channel open, so no one's access to one can end while their socket stays open. A channel there is none of, one whose record is not public and one of a resource with members are refused alike with `404`; a record only some people may read takes `members`. A ticket lists at most 200 channels (`400`, or `422` when the memberships are more).
91
101
 
@@ -97,7 +107,7 @@ The [dispatch](events.md) that turns each transaction's changes into events also
97
107
  { "kind": "create", "resource": "messages", "key": "42", "channel": "conversations/7", "mentions": ["u2"] }
98
108
  ```
99
109
 
100
- `kind` is `create`, `update`, `delete` or `undelete`; `mentions` is there with `mentions` set. A notice tells clients what changed, so they read only the records they show. On a channel with members it reaches its members as the database holds them at dispatch, in the members resource or `realtime.members`, and a person who joined or left with that change; on an open channel, everyone joined to it, while the anonymous role reads its record as it stands at dispatch. The relay sends a notice once, however often the job sends it again.
110
+ `kind` is `create`, `update`, `delete` or `undelete`; `mentions` is there with `mentions` set. A notice tells clients what changed, so they read only the records they show. On a channel with members it reaches its members as the database holds them at dispatch, in the members resource or `realtime.members`, or the members of its organization for an [organization-wide](#organization-wide-channels) record, and a person who joined or left with that change; on an open channel, everyone joined to it, while the anonymous role reads its record as it stands at dispatch. The relay sends a notice once, however often the job sends it again.
101
111
 
102
112
  A members record that is created or undeleted adds its person to the channel on the sockets they have open, before its notice, and one that is deleted or soft-deleted takes them out after it; a channel record that lists its members does the same for each person its change adds to or drops from the list: they can join, or are closed out, without connecting again. The person added, and no one else, also hears a `joined` event on `people` that names the channel, `{ "channel": "conversations/7" }`, so their pages join it. Commands go in commit order, one job at a time; while the relay is down, they wait and try again, once a minute at most. A command the relay refuses, such as one over its size limit, goes to the app's error reporter and is passed over.
103
113
 
@@ -127,7 +137,7 @@ The relay posts its reports to `POST /api/relay/presence` with the presence key
127
137
 
128
138
  Each write goes through the resource's table, so its changes raise the resource's [events](events.md), [webhooks](webhooks.md) and [workflows](workflows.md) as any other record's do, such as a workflow on `presences.wentOffline`. An offline report raises its event once.
129
139
 
130
- Each change of a person's presence is also published on `people` as a `presence_changed` event, the same bytes to everyone who shares a channel with members with them, themselves included, as the members tables and `realtime.members` hold it at dispatch, read for the whole batch in one query:
140
+ Each change of a person's presence is also published on `people` as a `presence_changed` event, the same bytes to everyone who shares a channel with members with them, themselves included, as the members tables and `realtime.members` hold it at dispatch, everyone in an organization of theirs with an [organization-wide](#organization-wide-channels) channel included, read for the whole batch in one query:
131
141
 
132
142
  ```json
133
143
  { "user": "u1", "status": "offline", "at": "2026-11-21T10:00:00.000Z" }