@protobase/cli 0.94.18 → 0.94.19

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.94.18";
2
+ var version = "0.94.19";
3
3
  //#endregion
4
4
  export { version };
@@ -1,5 +1,5 @@
1
1
  import { authMigrationTitle } from "../auth/migration-file.js";
2
- import { authSchemaMigration, callsMigration, changesMigration, channelSendsMigration, commentsMigration, computedMigration, derivedMigration, isCaptured, jobsSchemaMigration, notificationsMigration, ownedDefinitionsMigration, queryRunnerMigration, realtimeRelayMigration, relayed, sqlSends, statusMigration, userTablesMigration, webhooksMigration, workflowsMigration } from "@protobase/server";
2
+ import { authSchemaMigration, callsMigration, capturedBy, changesMigration, channelSendsMigration, commentsMigration, computedMigration, derivedMigration, jobsSchemaMigration, notificationsMigration, ownedDefinitionsMigration, queryRunnerMigration, realtimeRelayMigration, relayed, sqlSends, statusMigration, userTablesMigration, webhooksMigration, workflowsMigration } from "@protobase/server";
3
3
  //#region src/migration/parts.ts
4
4
  /** Every feature the project's config enables, in the order their files are written. */
5
5
  const migrationParts = (project) => {
@@ -11,7 +11,7 @@ const migrationParts = (project) => {
11
11
  title: authMigrationTitle,
12
12
  sql: () => authSchemaMigration(project.auth)
13
13
  }] : [],
14
- ...project.jobs.length > 0 || project.models.some(isCaptured) || comments || aiFields || project.webhooks || project.workflows || project.notifications ? [{
14
+ ...project.jobs.length > 0 || project.models.some(capturedBy(project.models)) || comments || aiFields || project.webhooks || project.workflows || project.notifications ? [{
15
15
  name: "jobs",
16
16
  title: "The jobs schema this version of Protobase needs",
17
17
  sql: () => jobsSchemaMigration(project.db)
@@ -26,7 +26,7 @@ const startWorker = async ({ config, databaseUrl, openDb = (url) => openAppDatab
26
26
  const project = await buildProject(config, database);
27
27
  const builtIn = configExports(project.config).resources.some((resource) => {
28
28
  const model = resource.toModel();
29
- return isCaptured(model) || model.comments || Object.values(model.fields).some((field) => field.ai);
29
+ return isCaptured(model) || model.live || model.comments || Object.values(model.fields).some((field) => field.ai);
30
30
  });
31
31
  if (project.jobs.length === 0 && !builtIn) throw new Error("The bundle has no jobs: name their module in protobase.config.ts as `jobs`, or give a resource events, history, comments or an AI field");
32
32
  const { admin, jobs: definitions } = projectAdmin(project, db);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.94.18",
3
+ "version": "0.94.19",
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.94.18",
47
- "@protobase/layout": "0.94.18",
48
- "@protobase/query": "0.94.18",
49
- "@protobase/schema": "0.94.18",
50
- "@protobase/server": "0.94.18",
51
- "@protobase/ui": "0.94.18",
52
- "@protobase/workflows": "0.94.18",
46
+ "@protobase/config": "0.94.19",
47
+ "@protobase/layout": "0.94.19",
48
+ "@protobase/query": "0.94.19",
49
+ "@protobase/schema": "0.94.19",
50
+ "@protobase/server": "0.94.19",
51
+ "@protobase/ui": "0.94.19",
52
+ "@protobase/workflows": "0.94.19",
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",
@@ -11,6 +11,7 @@ The changes of each record, comments on it, and pages that refresh as records ch
11
11
  - [Mentions](../reference/comments.md#mentions): Mentioning a colleague in a comment sends them an email with a link to the record.
12
12
  - [Comment moderation](../reference/comments.md#moderation): Admins find and delete comments across the app.
13
13
  - [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.
14
+ - [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.
14
15
  - [Change stream](../reference/live.md#the-stream): Apps follow record changes over a stream that catches up after a reconnect.
15
16
  - [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.
16
17
  - [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.
@@ -43,6 +43,35 @@ It is live data, not multiplayer editing: two people editing the same record sti
43
43
 
44
44
  Connecting again with `?after=<cursor>` catches up on what was missed while disconnected. [`client.live({ onChanges, onResync })`](client.md) of `@protobase/client` follows the stream and connects again by itself, as the app does. However many callers of one client follow it, they share one stream, so a page with many live views holds one connection, which matters under HTTP/1.1, where a browser opens at most six to a host.
45
45
 
46
+ ## Resources backed by a view
47
+
48
+ :::caution[Experimental]
49
+ A view's change names no record, so the [Realtime socket](supabase-realtime.md) does not send it.
50
+ :::
51
+
52
+ A resource backed by a database view, such as a chat thread that merges messages and replies, updates live when the tables it reads change. A view takes no trigger, so name the resources it reads with `.live({ reads })`: a change in any of them refreshes the view's open lists, record pages and related lists, and a change in another table does not.
53
+
54
+ ```ts title="config/thread.ts"
55
+ import { f, resource } from '@protobase/schema'
56
+
57
+ // A chat thread over a view merging messages and replies: an open thread shows a new message or reply within a second or two.
58
+
59
+ /** thread */
60
+ export const thread = resource('thread')
61
+ .table('thread')
62
+ .fields({
63
+ id: f.text().filterable(),
64
+ body: f.text(),
65
+ sent_at: f.timestamp().sortable(),
66
+ })
67
+ .primaryKey((r) => r.id)
68
+ .live({ reads: ['messages', 'replies'] })
69
+ ```
70
+
71
+ Each resource it names is captured like a live one, needs no `.live()` of its own and still needs a resource of its own; `protobase dev` and `protobase serve` do not start when a name is not a resource, or is another resource backed by a view: name the tables that view reads instead. The stream sends the view a change with an empty key, `{ resource, key: '', operation: 'update' }`, once for writes that come close together: any of its records may have changed, so the page reads what it shows of the view again. A reader hears of it in the tenant of the record that changed, or in every tenant when that resource has no tenant.
72
+
73
+ <gap>A view cannot update live from a table without a resource because the capture of plain tables is not implemented.</gap>
74
+
46
75
  ## Polling, then a socket
47
76
 
48
77
  `pollThenSocket({ poll, onError, socket, onMessage, pollMs?, switchAfterMs?, socketFirst? })` of `@protobase/client`, in the browser and on Node, keeps up with anything that changes, until the function it returns is called. It calls `poll` at once and again `pollMs` (5 seconds) after each call ends, also after one that rejected, whose error goes to `onError`, and after `switchAfterMs` (30 seconds) opens the WebSocket `socket()` returns, such as `() => new WebSocket(url)`. Once the socket is open, polling stops: `poll` runs once more, for what changed before the socket opened, and `onMessage` gets each message's data. When the socket closes, or never opens, it polls again at once and opens a new socket `switchAfterMs` later. Polling goes on while a socket connects, so nothing waits on it. A short visit thus never opens a socket; `socketFirst: true` opens one at once instead, for a process that stays, and polls only while it is down.
@@ -51,6 +80,6 @@ Who is on a record's page and what they send each other, which no change of a re
51
80
 
52
81
  ## The table
53
82
 
54
- [`protobase migration`](cli.md#migration) adds the table `changes.notices` to the `changes` schema of the event capture (renamed with `events: { schema }`), and the capture triggers of each live resource; apply it with the project's other migrations. `protobase dev` and `protobase serve` do not start while the table or a trigger is missing.
83
+ [`protobase migration`](cli.md#migration) adds the table `changes.notices` to the `changes` schema of the event capture (renamed with `events: { schema }`), and the capture triggers of each live resource and of each resource a live view reads; apply it with the project's other migrations. `protobase dev` and `protobase serve` do not start while the table or a trigger is missing.
55
84
 
56
85
  A notice is a resource, a record key, the record's tenant and the operation, written by the `changes.dispatch` job in the transaction that removes the change from the outbox; a live resource therefore needs the [`jobs` schema](jobs.md#the-jobs-schema) and the app's workers. Notices are kept for 10 minutes. Each serving process with at least one page open reads the table once a second, however many pages it serves, so live updates work with several serving processes, with `PROTOBASE_JOBS=false` and through a pooler in transaction mode.