@protobase/cli 0.54.1 → 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.
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "0.54.1";
2
+ var version = "0.54.2";
3
3
  //#endregion
4
4
  export { version };
@@ -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
- await (await vite.ssrLoadModule(support)).stopDevJobs();
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
- export { apiWebSocketServer, stopDevJobs };
3
+ import { stopDevRealtimePrune } from "./dev-prune.js";
4
+ export { apiWebSocketServer, stopDevJobs, stopDevRealtimePrune };
@@ -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,5 @@
1
+ import "@protobase/server";
2
+ //#region src/dev/dev-prune.d.ts
3
+ /** Stops the prune, after one in progress, when the dev server closes. */
4
+ export declare const stopDevRealtimePrune: () => Promise<void>;
5
+ //#endregion
@@ -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);
@@ -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.1",
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.1",
46
- "@protobase/layout": "0.54.1",
47
- "@protobase/query": "0.54.1",
48
- "@protobase/schema": "0.54.1",
49
- "@protobase/server": "0.54.1",
50
- "@protobase/ui": "0.54.1",
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",
@@ -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`. <gap>Messages sent while no socket is open stay in `realtime.messages` until one opens, because nothing else prunes the table.</gap> <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>
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