@protobase/cli 0.133.1 → 0.133.3
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.
- package/dist/build/bundle-changes.js +17 -0
- package/dist/build/deploy-bundle.js +3 -1
- package/dist/bundle/manifest.js +6 -2
- package/dist/cli/package.js +1 -1
- package/package.json +8 -8
- package/skills/protobase/references/features/history-comments-and-live-updates.md +3 -0
- package/skills/protobase/references/guides/api-functions.md +2 -1
- package/skills/protobase/references/reference/cli.md +6 -0
- package/skills/protobase/references/reference/config/jobs-and-events.md +11 -0
- package/skills/protobase/references/reference/events.md +13 -0
- package/skills/protobase/references/reference/live.md +35 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/build/bundle-changes.ts
|
|
2
|
+
const changeResource = (model) => {
|
|
3
|
+
const column = (field) => model.fields[field].column;
|
|
4
|
+
return {
|
|
5
|
+
table: {
|
|
6
|
+
schema: model.table.schema ?? null,
|
|
7
|
+
name: model.table.name
|
|
8
|
+
},
|
|
9
|
+
key: model.primaryKey.map(column),
|
|
10
|
+
tenant: model.tenant ? column(model.tenant) : null,
|
|
11
|
+
personal: model.owner ? [column(model.owner)] : []
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
/** The change model of `models`, so a reader of the WAL names each changed row's resource without the app's code. */
|
|
15
|
+
const bundleChanges = (models) => ({ resources: Object.fromEntries(models.map((model) => [model.name, changeResource(model)])) });
|
|
16
|
+
//#endregion
|
|
17
|
+
export { bundleChanges };
|
|
@@ -2,6 +2,7 @@ import { bundleProtobaseVersion } from "../version/project-version.js";
|
|
|
2
2
|
import { protobaseFolder } from "../project/protobase-folder.js";
|
|
3
3
|
import { buildIcons } from "./app-icons.js";
|
|
4
4
|
import { bundleLayout, bundleMigrations, bundleNodeModules, manifestFile } from "../bundle/manifest.js";
|
|
5
|
+
import { bundleChanges } from "./bundle-changes.js";
|
|
5
6
|
import { buildBundlePlugins } from "./bundle-plugins.js";
|
|
6
7
|
import { copyMigrations } from "./bundle-migrations.js";
|
|
7
8
|
import { buildConfigBundle } from "./config-bundle.js";
|
|
@@ -108,7 +109,8 @@ const buildDeployBundle = async ({ projectDir, outDir, bun, extensions = [], sou
|
|
|
108
109
|
...mobileSection && { mobile: mobileSection },
|
|
109
110
|
...packages.length > 0 ? { nodeModules: bundleNodeModules } : {},
|
|
110
111
|
...migrations ? { migrations } : {},
|
|
111
|
-
...realtimePart && { realtime: realtimePart }
|
|
112
|
+
...realtimePart && { realtime: realtimePart },
|
|
113
|
+
changes: bundleChanges(models)
|
|
112
114
|
};
|
|
113
115
|
await writeFile(path.join(outDir, manifestFile), `${JSON.stringify(manifest, null, 2)}\n`);
|
|
114
116
|
return manifest;
|
package/dist/bundle/manifest.js
CHANGED
|
@@ -22,11 +22,13 @@ const isShell = (value) => isObject(value) && typeof value.protobase === "string
|
|
|
22
22
|
const isTime = (value) => Number.isSafeInteger(value) && value >= 0;
|
|
23
23
|
const isVersions = (value) => isObject(value) && Object.values(value).every((item) => typeof item === "string");
|
|
24
24
|
const isRealtime = (value) => isObject(value) && (value.client_events === void 0 || isObject(value.client_events) && isObject(value.client_events.channels)) && (value.presence === void 0 || isObject(value.presence) && typeof value.presence.path === "string" && Number.isInteger(value.presence.grace_seconds));
|
|
25
|
+
const isChangeResource = (value) => isObject(value) && isObject(value.table) && (value.table.schema === null || typeof value.table.schema === "string") && typeof value.table.name === "string" && isStringList(value.key) && (value.tenant === null || typeof value.tenant === "string") && isStringList(value.personal);
|
|
26
|
+
const isChanges = (value) => isObject(value) && isObject(value.resources) && Object.values(value.resources).every(isChangeResource);
|
|
25
27
|
const isIcons = (value) => isObject(value) && typeof value.favicon === "boolean" && isStringList(value.png) && value.png.every((icon) => icon in pngIcons);
|
|
26
28
|
const parseManifest = (value, file) => {
|
|
27
29
|
const manifest = value;
|
|
28
30
|
if (manifest?.version !== 3) throw new Error(`${file} is not a version 3 bundle manifest; rebuild it with \`protobase build\``);
|
|
29
|
-
const { builtAt, server, public: publicDir, api, spa, plugins, theme, shell, icons, native, mobile, nodeModules, migrations, realtime } = manifest;
|
|
31
|
+
const { builtAt, server, public: publicDir, api, spa, plugins, theme, shell, icons, native, mobile, nodeModules, migrations, realtime, changes } = manifest;
|
|
30
32
|
if (typeof server !== "string" || typeof publicDir !== "string" || typeof spa !== "string" || typeof theme !== "string" || !isStringList(api)) throw new Error(`${file} needs server, public, spa and theme paths and an api list`);
|
|
31
33
|
if (!Array.isArray(plugins) || !plugins.every(isPlugin)) throw new Error(`${file} needs a plugins list, each with a name, path and api`);
|
|
32
34
|
if (!isShell(shell)) throw new Error(`${file} needs a shell with its protobase version, pluginApi and paths`);
|
|
@@ -37,6 +39,7 @@ const parseManifest = (value, file) => {
|
|
|
37
39
|
if (nodeModules !== void 0 && typeof nodeModules !== "string") throw new Error(`${file} has a nodeModules that is no path`);
|
|
38
40
|
if (migrations !== void 0 && typeof migrations !== "string") throw new Error(`${file} has a migrations that is no path`);
|
|
39
41
|
if (realtime !== void 0 && !isRealtime(realtime)) throw new Error(`${file} has a realtime that is not { client_events, presence } with its channels and a presence path and grace`);
|
|
42
|
+
if (changes !== void 0 && !isChanges(changes)) throw new Error(`${file} has a changes that is not { resources } with each resource's table, key, tenant and personal columns`);
|
|
40
43
|
return {
|
|
41
44
|
version: 3,
|
|
42
45
|
...builtAt !== void 0 && { builtAt },
|
|
@@ -52,7 +55,8 @@ const parseManifest = (value, file) => {
|
|
|
52
55
|
...mobile && { mobile },
|
|
53
56
|
...nodeModules === void 0 ? {} : { nodeModules },
|
|
54
57
|
...migrations === void 0 ? {} : { migrations },
|
|
55
|
-
...realtime && { realtime }
|
|
58
|
+
...realtime && { realtime },
|
|
59
|
+
...changes && { changes }
|
|
56
60
|
};
|
|
57
61
|
};
|
|
58
62
|
const readManifest = async (bundleDir) => {
|
package/dist/cli/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.133.
|
|
3
|
+
"version": "0.133.3",
|
|
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.
|
|
47
|
-
"@protobase/layout": "0.133.
|
|
48
|
-
"@protobase/query": "0.133.
|
|
49
|
-
"@protobase/schema": "0.133.
|
|
50
|
-
"@protobase/server": "0.133.
|
|
51
|
-
"@protobase/ui": "0.133.
|
|
52
|
-
"@protobase/workflows": "0.133.
|
|
46
|
+
"@protobase/config": "0.133.3",
|
|
47
|
+
"@protobase/layout": "0.133.3",
|
|
48
|
+
"@protobase/query": "0.133.3",
|
|
49
|
+
"@protobase/schema": "0.133.3",
|
|
50
|
+
"@protobase/server": "0.133.3",
|
|
51
|
+
"@protobase/ui": "0.133.3",
|
|
52
|
+
"@protobase/workflows": "0.133.3",
|
|
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",
|
|
@@ -13,8 +13,11 @@ 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.
|
|
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.
|
|
16
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.
|
|
17
19
|
- [Change stream](../reference/live.md#the-stream): Apps follow record changes over a stream that catches up after a reconnect.
|
|
20
|
+
- [Changes in the write-ahead log](../reference/events.md#what-the-write-ahead-log-carries) (in development): A reader of the database's write-ahead log learns who made each change and, when switched on, each schema change, from logical messages in the change's own transaction, and maps each table to its resource from the change model `protobase build` writes into the bundle's manifest.
|
|
18
21
|
- [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
22
|
- [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
23
|
- [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.
|
|
@@ -54,9 +54,10 @@ The second argument of a handler (`c.env` in a [Hono app](#hono-apps)):
|
|
|
54
54
|
| `acceptWebSocket(events)` | Answers a WebSocket upgrade with a socket; return its response. See [WebSockets](#websockets). |
|
|
55
55
|
| `calls.join(member)` | The events of a member's socket in a call, for `acceptWebSocket`. See [Calls](../reference/calls.md). |
|
|
56
56
|
| `channels` | `channels.broadcast({ resource, key, event, payload })` sends to whoever is on a record's [channel](../reference/channels.md#from-the-server), as the server. |
|
|
57
|
+
| `live` | `live.refresh({ user })` tells a person's open pages to read again once their access changed. See [Refreshing access](../reference/live.md#refreshing-access). |
|
|
57
58
|
| `name` | The function's name. |
|
|
58
59
|
|
|
59
|
-
A [public function](#public-functions-and-webhooks) has only `db`, `caller()`, `acceptWebSocket`, `calls`, `channels` and `name`.
|
|
60
|
+
A [public function](#public-functions-and-webhooks) has only `db`, `caller()`, `acceptWebSocket`, `calls`, `channels`, `live` and `name`.
|
|
60
61
|
|
|
61
62
|
### The organization's tables
|
|
62
63
|
|
|
@@ -293,6 +293,11 @@ By default the bundle runs on Node and on Bun. `--bun` makes it a bundle for Bun
|
|
|
293
293
|
"realtime": {
|
|
294
294
|
"client_events": { "channels": { "conversations": { "events": { "typing": { "schema": { "type": "object" }, "max_bytes": 256, "per_second": 2, "burst": 4 } } } } },
|
|
295
295
|
"presence": { "path": "/api/relay/presence", "grace_seconds": 30 }
|
|
296
|
+
},
|
|
297
|
+
"changes": {
|
|
298
|
+
"resources": {
|
|
299
|
+
"orders": { "table": { "schema": null, "name": "orders" }, "key": ["id"], "tenant": "organization_id", "personal": ["owner_id"] }
|
|
300
|
+
}
|
|
296
301
|
}
|
|
297
302
|
}
|
|
298
303
|
```
|
|
@@ -307,6 +312,7 @@ By default the bundle runs on Node and on Bun. `--bun` makes it a bundle for Bun
|
|
|
307
312
|
- `nodeModules` is present only when the config module imports [native packages](#native-packages). It is always the `node_modules` folder beside `server`, where Bun and Node resolve the module's imports from, and holds plain packages: JavaScript, `package.json` files and native binaries for linux x64 and arm64 (glibc), which the runtime loads with `dlopen`. A host keeps it next to the server module and must not mount it `noexec` (an add-on there then fails with `failed to map segment from shared object`). Its binaries link nothing but glibc, `libstdc++.so.6`, `libgcc_s.so.1` and libraries in the bundle itself, so the run image must have those three. Without `nodeModules`, the server module is the only file the runtime reads.
|
|
308
313
|
- `migrations` is present only when the project has a `db/migrations` folder: its `.sql` files, which the runtime's `migrate` applies (see [Deploy](../guides/deploy.md)). A host never serves it.
|
|
309
314
|
- `realtime` is present only when the config has [`realtime.relay`](realtime-relay.md), or the app has sign-in and a live resource whose conversation page has `members`, which [the platform's switch](realtime-relay.md#from-the-platform) can move to the relay: the app's part of its entry in the apps file of Protobase Realtime, the WebSocket relay, as [`relay app`](#relay-app) prints it, without the address, id or any key: `client_events`, when a channel resource has events, and with presence `presence`, the path of the app's presence endpoint and the reports' `grace_seconds`. A host that runs Realtime completes it with the app's id, keys, origin and presence key, and the presence endpoint at the app's address.
|
|
315
|
+
- `changes` is the change model a reader of the database's write-ahead log maps rows by (see [What the write-ahead log carries](events.md#what-the-write-ahead-log-carries)): every resource of the config folder, by name, with its `table`, whose `schema` is `null` when the search path decides, and as column names its `key` in order, its `tenant` column or `null`, and in `personal` the column of its [owner](data-config.md), `[]` without one. A bundle built before it names none. <gap>The change model cannot name the built-in resources, such as the users or the comments, because reading them without running `protobase.config.ts` is not implemented.</gap>
|
|
310
316
|
- `api` lists the path prefixes the server answers. A path is under a prefix when it equals it or continues it with `/` (`/api` covers `/api/meta` and `/api/v1:batchWrite`, not `/apiary`). It is always `/api` and the two OAuth discovery documents [MCP clients](auth.md#oauth-for-mcp-clients) read, which answer 404 without MCP: a bundle assumes the API lives under `/api`, with the resources at the default `apiPath` `/api/v1`, `/api/meta`, the docs, the API functions and the built-in assistant beside them and Better Auth at `/api/auth`. A bundle built before them sends them to the UI: rebuild it. The serve runtime refuses a config that sets another `apiPath`.
|
|
311
317
|
- Every other path is the UI's. A `GET` or `HEAD` for a file in `public` gets that file; a folder gets its `index.html`. Otherwise a request whose `Accept` header contains `text/html` (a navigation) gets `spa` with status 200, so deep links such as `/orders/42` load the app; anything else gets 404. Other methods get 405.
|
|
312
318
|
- Files under an `assets/` folder, `public/assets/` and each plugin's, are named by their content hash and never change: serve them with `Cache-Control: public, max-age=31536000, immutable`, and everything else, `index.html`, each `plugin.json` and the theme, with `no-cache`.
|
|
@@ -154,6 +154,17 @@ The schema holding the outbox and the capture function that resources' [events](
|
|
|
154
154
|
export default defineConfig({ events: { schema: 'app_changes' } })
|
|
155
155
|
```
|
|
156
156
|
|
|
157
|
+
## events.stream
|
|
158
|
+
|
|
159
|
+
- **Type:** `boolean`
|
|
160
|
+
- **Default:** `false`
|
|
161
|
+
|
|
162
|
+
Whether `protobase migration` writes the event triggers that put each schema change into the write-ahead log as a logical message, which a reader of the log meets in order with the rows. Creating them takes a superuser. See [What the write-ahead log carries](../events.md#what-the-write-ahead-log-carries).
|
|
163
|
+
|
|
164
|
+
```ts
|
|
165
|
+
export default defineConfig({ events: { stream: true } })
|
|
166
|
+
```
|
|
167
|
+
|
|
157
168
|
## history.days
|
|
158
169
|
|
|
159
170
|
- **Type:** `number`, a positive whole number
|
|
@@ -100,6 +100,19 @@ For a database that already has a schema named `changes`, pick another name in `
|
|
|
100
100
|
export default defineConfig({ events: { schema: 'row_changes' } })
|
|
101
101
|
```
|
|
102
102
|
|
|
103
|
+
## What the write-ahead log carries
|
|
104
|
+
|
|
105
|
+
A reader of the database's write-ahead log (WAL), such as a logical replication client, can name each changed row's resource and who changed it without any table of Protobase's: Protobase writes it there as logical decoding messages, transactional ones, so each arrives with its transaction's rows, in their order, and only once it commits.
|
|
106
|
+
|
|
107
|
+
- **`protobase_actor`**: the API emits it at the start of every write transaction it runs for a caller, a single write, a batch, a comment, a write through the [PostgREST-compatible API](supabase-rest.md) or the storage API, in the same statement that sets the transaction's settings, so it costs no round trip. Its content is the caller as `changes.actor` holds it, such as `{"id":"u1","roles":["admin"]}`; the PostgREST-compatible and storage APIs name their signed-in user only, with no roles, and emit none for an anonymous caller or the app's own key. A write of the app's own background work, or from outside the API, has no `protobase_actor` message.
|
|
108
|
+
- **`protobase_ddl`** and **`protobase_drop`**: with `events: { stream: true }`, `protobase migration` writes `changes.emit_schema_messages()` and two event triggers, `changes_ddl_messages` and `changes_drop_messages` (the prefix is the events schema). A schema change then emits a `protobase_ddl` message for each command it runs, such as `{"command_tag": "ALTER TABLE", "object_type": "table", "schema_name": "public", "object_identity": "public.orders"}`, and a `protobase_drop` message for each object it drops, such as `{"object_type": "table", "schema_name": "public", "object_identity": "public.orders"}`, in Postgres's own words. A table's new columns come from the relation message logical decoding sends before its next row. Creating an event trigger takes a superuser, so the migration fails, and rolls back, as any other role.
|
|
109
|
+
|
|
110
|
+
The messages need no `wal_level` setting to be written; reading them needs `wal_level = logical`. Which table holds which resource, its key, tenant and owner columns, is in the bundle's [change model](cli.md#the-manifest).
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
export default defineConfig({ events: { stream: true } })
|
|
114
|
+
```
|
|
115
|
+
|
|
103
116
|
## Migrations and startup
|
|
104
117
|
|
|
105
118
|
[`protobase migration`](cli.md#migration) writes what the project's `protobase.snapshot.json` lacks of the change capture as the project's next migration: the jobs schema, then the `changes` schema with the outbox, the function, and a trigger pair per resource with events, each a module with numbered steps that the snapshot and the record of migrations hold. Apply it with the project's other migrations. A trigger changes when the resource's fields do, a field that became sensitive for instance, so run the command after changing the config. Once a resource has no events, it keeps its triggers while another resource is still captured, so the code still running drains what they capture, and the migration once none is drops them, saying it breaks older code; it never drops a table. <gap>`protobase migration` cannot refuse a trigger of the app's own named like the capture's, `<table>_changes` or `<table>_changes_update`, which the file replaces, because reading the database's triggers before writing is not implemented.</gap>
|
|
@@ -40,9 +40,44 @@ It is live data, not multiplayer editing: two people editing the same record sti
|
|
|
40
40
|
| `current` | Nothing new up to `cursor`. Sent first, and every 25 seconds. |
|
|
41
41
|
| `changes` | `changes`: `[{ resource, key, operation }]` in commit order, `operation` being `create`, `update`, `delete` or `undelete`. |
|
|
42
42
|
| `resync` | Changes went by that are no longer kept: read everything shown again. |
|
|
43
|
+
| `refresh` | The caller's access changed, through [`live.refresh`](#refreshing-access): read everything shown again. The stream then ends, so the page connects again with `?after=<cursor>` and hears what its access allows now. |
|
|
43
44
|
|
|
44
45
|
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
46
|
|
|
47
|
+
## Live tokens
|
|
48
|
+
|
|
49
|
+
:::caution[In development]
|
|
50
|
+
Reads give live tokens, but nothing takes them yet: subscribing with a token is coming soon.
|
|
51
|
+
:::
|
|
52
|
+
|
|
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`.
|
|
54
|
+
|
|
55
|
+
The token is a JWE (`dir`, A256GCM), so its holder can neither read nor change it. It holds:
|
|
56
|
+
|
|
57
|
+
| Claim | |
|
|
58
|
+
| --- | --- |
|
|
59
|
+
| `resource` | The resource read. |
|
|
60
|
+
| `where` | What the read keeps to, as [filter](api.md#filters) text on the row alone: the soft delete, the tenant, the access row filter, the parents the caller must read, the caller's own filter, and a record read's key. Left out when nothing is kept out. |
|
|
61
|
+
| `fields` | The fields the read returned. |
|
|
62
|
+
| `snapshot` | The read's `pg_current_snapshot()`. The whole read runs in one REPEATABLE READ snapshot, so the token tells exactly which transactions the rows include. |
|
|
63
|
+
| `sub`, `sid` | The signed-in person and their sign-in session, which the token is bound to. |
|
|
64
|
+
| `anonymous` | `true` for a visitor's token, which is bound to no session. |
|
|
65
|
+
| `iat`, `exp` | When it was issued and when it expires. |
|
|
66
|
+
|
|
67
|
+
A signed-in person's token expires when their session ends, after an hour at most. A visitor's token lasts an hour, longer than any cache time of the API, which lets none. An API key, an outside app acting for a person and a caller without a session of the app get no token. The token is sealed with a key derived from the [relay](realtime-relay.md)'s ticket key, so an app without a relay gives none.
|
|
68
|
+
|
|
69
|
+
Conditions that read other rows are evaluated when the token is issued: a parent the caller must read, a `related()` term and a lookup field become the list of keys they match at that moment, such as `in(project_id, 4, 9)`. A record that starts to match one of them later is not in the token, and a role or membership change does not change a token already issued; [refresh](#refreshing-access) the person's pages instead.
|
|
70
|
+
|
|
71
|
+
The server gives no token, and no `Preference-Applied`, when it cannot write the read as conditions on the row alone. <gap>A read cannot get a live token when a record-level read rule decides it, or when it searches a lookup field, because writing those as conditions on the row alone is not implemented.</gap> <gap>A read cannot get a live token longer than 3,000 bytes, such as one whose parents resolve to many keys, because subscribing to a list of keys that long is not implemented.</gap>
|
|
72
|
+
|
|
73
|
+
### Refreshing access
|
|
74
|
+
|
|
75
|
+
:::caution[In development]
|
|
76
|
+
Pages read again on a refresh; the tokens they get are not taken by anything yet.
|
|
77
|
+
:::
|
|
78
|
+
|
|
79
|
+
`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
|
+
|
|
46
81
|
## Resources backed by a view
|
|
47
82
|
|
|
48
83
|
:::caution[Experimental]
|