@protobase/cli 0.54.0 → 0.54.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.
- package/dist/cli/package.js +1 -1
- package/dist/dev/api-process.js +3 -1
- package/dist/dev/api-support.d.ts +2 -1
- package/dist/dev/api-support.js +2 -1
- package/dist/dev/dev-prune.d.ts +5 -0
- package/dist/dev/dev-prune.js +18 -0
- package/dist/dev/entry.js +2 -0
- package/dist/serve/lifecycle.js +3 -1
- package/package.json +7 -7
- package/skills/protobase/references/features/your-own-code.md +1 -0
- package/skills/protobase/references/reference/auth.md +1 -1
- package/skills/protobase/references/reference/custom-components.md +25 -0
- package/skills/protobase/references/reference/supabase-realtime.md +2 -2
package/dist/cli/package.js
CHANGED
package/dist/dev/api-process.js
CHANGED
|
@@ -46,7 +46,9 @@ const listen = (server) => new Promise((resolve, reject) => {
|
|
|
46
46
|
const stop = async () => {
|
|
47
47
|
server?.close();
|
|
48
48
|
server?.closeAllConnections();
|
|
49
|
-
|
|
49
|
+
const devSupport = await vite.ssrLoadModule(support);
|
|
50
|
+
await devSupport.stopDevJobs();
|
|
51
|
+
await devSupport.stopDevRealtimePrune();
|
|
50
52
|
await vite.close();
|
|
51
53
|
process.exit(process.exitCode ?? 0);
|
|
52
54
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { apiWebSocketServer } from "../project/api-websocket-server.js";
|
|
2
2
|
import { stopDevJobs } from "./dev-jobs.js";
|
|
3
|
-
|
|
3
|
+
import { stopDevRealtimePrune } from "./dev-prune.js";
|
|
4
|
+
export { apiWebSocketServer, stopDevJobs, stopDevRealtimePrune };
|
package/dist/dev/api-support.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { stopDevJobs } from "./dev-jobs.js";
|
|
2
|
+
import { stopDevRealtimePrune } from "./dev-prune.js";
|
|
2
3
|
import { apiWebSocketServer } from "../project/api-websocket-server.js";
|
|
3
|
-
export { apiWebSocketServer, stopDevJobs };
|
|
4
|
+
export { apiWebSocketServer, stopDevJobs, stopDevRealtimePrune };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/dev/dev-prune.ts
|
|
2
|
+
const store = globalThis;
|
|
3
|
+
/**
|
|
4
|
+
* Prunes the realtime tables in the dev server, from its first load on; `realtime.processes` changed later is the
|
|
5
|
+
* prune's from the next start.
|
|
6
|
+
*/
|
|
7
|
+
const devRealtimePrune = (admin) => {
|
|
8
|
+
if (store.__protobaseRealtimePrune) return;
|
|
9
|
+
store.__protobaseRealtimePrune = admin.startRealtimePrune();
|
|
10
|
+
};
|
|
11
|
+
/** Stops the prune, after one in progress, when the dev server closes. */
|
|
12
|
+
const stopDevRealtimePrune = async () => {
|
|
13
|
+
const prune = store.__protobaseRealtimePrune;
|
|
14
|
+
delete store.__protobaseRealtimePrune;
|
|
15
|
+
await prune?.stop();
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
18
|
+
export { devRealtimePrune, stopDevRealtimePrune };
|
package/dist/dev/entry.js
CHANGED
|
@@ -3,6 +3,7 @@ import { projectIcons } from "../build/app-icons.js";
|
|
|
3
3
|
import { projectErrorReporter } from "../project/error-reporter.js";
|
|
4
4
|
import { projectAdmin } from "../project/project-admin.js";
|
|
5
5
|
import { devJobs } from "./dev-jobs.js";
|
|
6
|
+
import { devRealtimePrune } from "./dev-prune.js";
|
|
6
7
|
import { devDatabase, loadDevConfig } from "./project.js";
|
|
7
8
|
import { withDevServiceWorker } from "./service-worker-route.js";
|
|
8
9
|
import { setMissing, supabaseEnv } from "./supabase-env.js";
|
|
@@ -49,6 +50,7 @@ const ui = {
|
|
|
49
50
|
};
|
|
50
51
|
const { admin, jobs } = projectAdmin(project, db, ui, reporter, upgradeWebSocket);
|
|
51
52
|
await devJobs(db, jobs, project.mailer);
|
|
53
|
+
devRealtimePrune(admin);
|
|
52
54
|
var entry_default = withDevServiceWorker(new Hono(), Boolean(project.notifications)).route("/", admin);
|
|
53
55
|
/** Whether the auth store has a user yet, for the banner's sign-in line; undefined without one. */
|
|
54
56
|
const anyUsers = () => project.auth ? hasUsers(project.auth) : Promise.resolve(void 0);
|
package/dist/serve/lifecycle.js
CHANGED
|
@@ -83,11 +83,12 @@ const startServe = async ({ config, env, openDb = (url) => openAppDatabase(pg, u
|
|
|
83
83
|
server,
|
|
84
84
|
sockets,
|
|
85
85
|
jobs,
|
|
86
|
+
prune: admin.startRealtimePrune(),
|
|
86
87
|
resources,
|
|
87
88
|
files: project.files
|
|
88
89
|
};
|
|
89
90
|
};
|
|
90
|
-
const { server, sockets, jobs, resources, files } = await startJobsAndListen().catch(async (error) => {
|
|
91
|
+
const { server, sockets, jobs, prune, resources, files } = await startJobsAndListen().catch(async (error) => {
|
|
91
92
|
await db.destroy();
|
|
92
93
|
throw error;
|
|
93
94
|
});
|
|
@@ -103,6 +104,7 @@ const startServe = async ({ config, env, openDb = (url) => openAppDatabase(pg, u
|
|
|
103
104
|
await closed;
|
|
104
105
|
await backgroundSettled();
|
|
105
106
|
await timer?.stop();
|
|
107
|
+
await prune.stop();
|
|
106
108
|
await jobs?.stop();
|
|
107
109
|
await db.destroy();
|
|
108
110
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.54.
|
|
3
|
+
"version": "0.54.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": {
|
|
@@ -42,12 +42,12 @@
|
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@better-auth/core": "^1.7.12",
|
|
44
44
|
"@hono/node-server": "^2.1.3",
|
|
45
|
-
"@protobase/config": "0.54.
|
|
46
|
-
"@protobase/layout": "0.54.
|
|
47
|
-
"@protobase/query": "0.54.
|
|
48
|
-
"@protobase/schema": "0.54.
|
|
49
|
-
"@protobase/server": "0.54.
|
|
50
|
-
"@protobase/ui": "0.54.
|
|
45
|
+
"@protobase/config": "0.54.2",
|
|
46
|
+
"@protobase/layout": "0.54.2",
|
|
47
|
+
"@protobase/query": "0.54.2",
|
|
48
|
+
"@protobase/schema": "0.54.2",
|
|
49
|
+
"@protobase/server": "0.54.2",
|
|
50
|
+
"@protobase/ui": "0.54.2",
|
|
51
51
|
"@react-email/render": "^2.1.0",
|
|
52
52
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
53
53
|
"@tailwindcss/vite": "^4.3.3",
|
|
@@ -14,6 +14,7 @@ React components, field types, pages and handlers of your own, loaded as plugins
|
|
|
14
14
|
- [Image carousel](../reference/custom-components.md#image-carousel): Step through screenshots or a record's files in your own components by swiping or with arrows, as cards step through photos.
|
|
15
15
|
- [Assistant parts](../reference/assistant.md#in-the-ui): The assistant's panel, chat messages, composer and action cards for your own components, with a frameless action card for a page that is already framed.
|
|
16
16
|
- [Chat parts](../reference/custom-components.md#chat-parts): A chat between people from the app's parts: messages with their author, avatar, time and a status line, day and new-message lines, a thread that loads earlier messages, keeps the reader's place and jumps to the end when they send, and a composer of several lines with @mentions.
|
|
17
|
+
- [Members' names](../reference/custom-components.md#members-names): The names and photos of the organization's members by user id, for message authors and @mentions in your own components; every member reads them, without email addresses.
|
|
17
18
|
- [Action handlers](../reference/custom-components.md#action-handlers): Your own code for a named action, with the record, the API client and the action's inputs.
|
|
18
19
|
- [Shell slots](../reference/custom-components.md#shell-slots): Your own components in the top bar, in a panel beside every page, or as the sidebar logo.
|
|
19
20
|
- [Plugins](../reference/plugins.md#how-a-plugin-stays-working): Your React code is a plugin that the app loads at start and that keeps working across Protobase releases without changes.
|
|
@@ -597,7 +597,7 @@ It is Better Auth's organization plugin, with its tables named in snake_case (`o
|
|
|
597
597
|
|
|
598
598
|
**Invitations.** Better Auth's `POST /api/auth/organization/invite-member` with `{ organizationId, email, role, appRoles }`; inviting again replaces the earlier invitation, and it works for `invitationDays` (default 7). The email links to `{url}/-/invitation?token=…` (`invitationUrl`), with a token signed with the app's `secret`, since members can read invitation ids; without a mailer, the answer carries the `link` to pass on. The link page shows `GET /api/auth/invitation?token=`, accepts with `POST /api/auth/invitation/accept` for someone signed in as the invited address, and makes an account with `POST /api/auth/invitation/sign-up` (`{ token, name, password? }`) for an address without one. Someone signed in sees the invitations for their own address with Better Auth's `GET /api/auth/organization/list-user-invitations`, on the organizations page, and accepts one there with `POST /api/auth/invitation/accept-own` (`{ invitationId }`). The link page and its sign-up serve [invitations to the app](#users-page) too. [Open sign-up](#open-sign-up) is not available with organizations: an invitation is the address someone vouched for.
|
|
599
599
|
|
|
600
|
-
**Members.** Better Auth's `list-members`, `update-member-role`, `remove-member` and `leave`; `POST /api/auth/organization/set-app-roles` (`{ memberId, appRoles }`); `POST /api/auth/organization/transfer-ownership` (`{ memberId, keepAs? }`) makes a member owner and the caller an admin in one step. `GET /api/auth/organization/current` answers the organization a session works in with the caller's roles there.
|
|
600
|
+
**Members.** Better Auth's `list-members`, `update-member-role`, `remove-member` and `leave`; `POST /api/auth/organization/set-app-roles` (`{ memberId, appRoles }`); `POST /api/auth/organization/transfer-ownership` (`{ memberId, keepAs? }`) makes a member owner and the caller an admin in one step. `GET /api/auth/organization/current` answers the organization a session works in with the caller's roles there. `GET /api/auth/organization/people` answers the members of that organization to any of its members, as `{ people: [{ id, name, image? }] }` with `id` the user id and no email addresses; anyone who is not a member of it, signed out or with a global role only, is refused.
|
|
601
601
|
|
|
602
602
|
**Deleting** an organization (Better Auth's `delete`, owners only) is refused with `409 ORGANIZATION_HAS_RECORDS` while a `.tenant` resource has rows in it; `deleteRecords: 'cascade'` leaves it to the project's foreign keys. The `beforeOrganizationDeleted` [hook](#hooks) may refuse too.
|
|
603
603
|
|
|
@@ -310,6 +310,31 @@ export const Channel = ({ messages, sent, members, onSend, onLoadEarlier }: Chan
|
|
|
310
310
|
)
|
|
311
311
|
```
|
|
312
312
|
|
|
313
|
+
### Members' names
|
|
314
|
+
|
|
315
|
+
The author is a user id, and `useMembers()` from `@protobase/ui` turns it into a name: the members of the organization the signed-in person works in, `{ id, name, image? }` by name, with `id` the user id that `.author()` stores and that `onSend`'s mentions hold. Every member reads it, owners, admins and members alike; it holds no email addresses. It is a TanStack Query result (`data`, `isLoading`, `error`) with `member(id)`, which finds one and, for an id it does not know, such as a newcomer's first message, reads the list again once it is 10 seconds old; it is also read again when the window regains focus and the list is 30 seconds old. It needs [organizations](auth.md#organizations): without them, `error` says so.
|
|
316
|
+
|
|
317
|
+
```tsx
|
|
318
|
+
import { ChatMessage, Composer, MentionedText, useMembers } from '@protobase/ui'
|
|
319
|
+
|
|
320
|
+
export const Message = ({ message }: { message: { author_id: string; body: string; mentions: string[]; sent_at: string } }) => {
|
|
321
|
+
const { member } = useMembers()
|
|
322
|
+
return (
|
|
323
|
+
<ChatMessage author={{ id: message.author_id, name: member(message.author_id)?.name ?? '' }} time={message.sent_at}>
|
|
324
|
+
<MentionedText text={message.body} mentions={message.mentions.map((id) => ({ name: member(id)?.name }))} />
|
|
325
|
+
</ChatMessage>
|
|
326
|
+
)
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
export const ChannelComposer = ({ onSend }: { onSend: (text: string, mentions: string[]) => void }) => {
|
|
330
|
+
const { data: members = [] } = useMembers()
|
|
331
|
+
const searchPeople = async (query: string) => members.filter((person) => person.name.toLowerCase().includes(query.toLowerCase())).slice(0, 8)
|
|
332
|
+
return <Composer onSend={onSend} searchPeople={searchPeople} />
|
|
333
|
+
}
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
`searchPeople` filters the list in the browser and shows at most 8, as comments' mentions do. <gap>`useMembers()` cannot page or search on the server because a server-side people resource is not implemented, so the whole list loads in the browser, which suits a team, not thousands of members.</gap> <gap>Old messages of someone who has left the organization cannot show their name because looking up former members is not implemented.</gap> A person who works in an organization without being a member of it, through a global role, gets no list.
|
|
337
|
+
|
|
313
338
|
## Components in the chat
|
|
314
339
|
|
|
315
340
|
The same components draw the assistant's [widget parts](assistant.md#widget-parts): a part names a component, and the dock draws it with the part's props, so one component can sit on a page and in the chat. In the chat there is no record around it, so a component that needs `useLayoutRecord()` works only on pages; take ids as props instead. Besides the API hooks, a widget can read the assistant backend with [`useBackendData`](assistant.md#reading-the-backend-from-a-widget).
|
|
@@ -48,7 +48,7 @@ Limits, near Supabase's Free plan, apply per socket and per topic. A socket send
|
|
|
48
48
|
|
|
49
49
|
### Several processes
|
|
50
50
|
|
|
51
|
-
By default, one process serves the app, and broadcasts and presence go between its channels. When several processes serve it behind one address, set [`realtime: { processes: 'many' }`](config/api.md#realtime) and apply the migration [`protobase migration`](cli.md#migration) writes. Every channel on a topic then hears its broadcasts and presence, whichever process it joined, and so do broadcasts over the REST endpoint and from the database. Private and public channels of a topic stay apart across processes as on one. The processes share them through the `realtime_relay` schema of the app's database: each adds what it sends, and reads what the others sent ten times a second while one of its sockets is open, so a broadcast reaches another process's channels within about 100 ms. A topic's 100 broadcasts a second are counted across all the processes. A process that stops gracefully removes the presence its channels tracked; one that is killed has it removed by the others about 15 seconds after its last heartbeat, and their channels hear the leaves.
|
|
51
|
+
By default, one process serves the app, and broadcasts and presence go between its channels. When several processes serve it behind one address, set [`realtime: { processes: 'many' }`](config/api.md#realtime) and apply the migration [`protobase migration`](cli.md#migration) writes. Every channel on a topic then hears its broadcasts and presence, whichever process it joined, and so do broadcasts over the REST endpoint and from the database. Private and public channels of a topic stay apart across processes as on one. The processes share them through the `realtime_relay` schema of the app's database: each adds what it sends, and reads what the others sent ten times a second while one of its sockets is open, so a broadcast reaches another process's channels within about 100 ms. A topic's 100 broadcasts a second are counted across all the processes. Every 10 minutes, whether or not a socket is open, each process deletes the frames older than a minute and the counts of seconds before it. A process that stops gracefully removes the presence its channels tracked; one that is killed has it removed by the others about 15 seconds after its last heartbeat, and their channels hear the leaves.
|
|
52
52
|
|
|
53
53
|
### Broadcast without a channel
|
|
54
54
|
|
|
@@ -84,7 +84,7 @@ supabase
|
|
|
84
84
|
.subscribe()
|
|
85
85
|
```
|
|
86
86
|
|
|
87
|
-
Each call inserts a message into `realtime.messages` in the caller's transaction, as on Supabase, so a transaction rolled back sends nothing. Within a second of its commit, the server takes the message out of the table and sends it to the channels joined on its topic, in the order the transaction sent them, with the message's id in the payload's `id` and in the broadcast's `meta.id`. `broadcast_changes()` sends `{ operation, table, schema, record, old_record }`, `record` and `old_record` each the whole row or `null`. `private` is `true` unless the call says `false`, as on Supabase: a private message reaches only the topic's private channels whose [policies](#private-channels) let them receive broadcasts, and a public one only its public channels. A message goes under the topic's 100 broadcasts a second, and one whose topic or event is over 255 bytes or whose payload is over 256 KiB is dropped. The server reads the table while one of its sockets is open, and a message no channel hears is dropped, as on Supabase. A call as a role the policies on `realtime.messages` do not let insert sends nothing and raises a warning, as Supabase's does, so a trigger function that sends for its callers is `security definer`.
|
|
87
|
+
Each call inserts a message into `realtime.messages` in the caller's transaction, as on Supabase, so a transaction rolled back sends nothing. Within a second of its commit, the server takes the message out of the table and sends it to the channels joined on its topic, in the order the transaction sent them, with the message's id in the payload's `id` and in the broadcast's `meta.id`. `broadcast_changes()` sends `{ operation, table, schema, record, old_record }`, `record` and `old_record` each the whole row or `null`. `private` is `true` unless the call says `false`, as on Supabase: a private message reaches only the topic's private channels whose [policies](#private-channels) let them receive broadcasts, and a public one only its public channels. A message goes under the topic's 100 broadcasts a second, and one whose topic or event is over 255 bytes or whose payload is over 256 KiB is dropped. The server reads the table while one of its sockets is open, and a message no channel hears is dropped, as on Supabase. A call as a role the policies on `realtime.messages` do not let insert sends nothing and raises a warning, as Supabase's does, so a trigger function that sends for its callers is `security definer`. Every process serving the app deletes the broadcast messages more than 48 hours old, whether or not a socket is open: once it starts, then every 10 minutes. The margin covers `inserted_at`, a time without a zone, stamped in the sending session's time zone. <gap>A project that was not imported cannot call `realtime.send()` without making Supabase's functions in a migration of its own, because Protobase's migrations do not make them.</gap>
|
|
88
88
|
|
|
89
89
|
## Private channels
|
|
90
90
|
|