@protobase/server 0.123.3 → 0.123.4
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/package.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { AdminAuth } from "../better-auth/create-auth.js";
|
|
2
2
|
import { Db } from "@protobase/query";
|
|
3
3
|
//#region src/relay/relay-schema.d.ts
|
|
4
|
-
/**
|
|
5
|
-
|
|
4
|
+
/**
|
|
5
|
+
* The SQL the relay needs of the app's database: the trigger that closes a deleted session's sockets; `undefined` when
|
|
6
|
+
* it is current. `authWritten`: the same migration writes the auth store's steps before it.
|
|
7
|
+
*/
|
|
8
|
+
export declare const relayMigration: (db: Db, auth: AdminAuth | undefined, authWritten: boolean) => Promise<string | undefined>;
|
|
6
9
|
/** Refuses to start while the relay's trigger is missing or out of date. */
|
|
7
10
|
export declare const checkRelaySchema: (db: Db, auth: AdminAuth | undefined) => Promise<void>;
|
|
8
11
|
//#endregion
|
|
@@ -5,8 +5,11 @@ const needsAuth = (auth) => {
|
|
|
5
5
|
if (!auth) throw new Error("relay needs the app's own sign-in (auth), whose sessions its tickets name and end");
|
|
6
6
|
return auth;
|
|
7
7
|
};
|
|
8
|
-
/**
|
|
9
|
-
|
|
8
|
+
/**
|
|
9
|
+
* The SQL the relay needs of the app's database: the trigger that closes a deleted session's sockets; `undefined` when
|
|
10
|
+
* it is current. `authWritten`: the same migration writes the auth store's steps before it.
|
|
11
|
+
*/
|
|
12
|
+
const relayMigration = (db, auth, authWritten) => relaySessionsMigration(db, sessionsTable(needsAuth(auth)), authWritten);
|
|
10
13
|
/** Refuses to start while the relay's trigger is missing or out of date. */
|
|
11
14
|
const checkRelaySchema = (db, auth) => checkRelaySessions(db, sessionsTable(needsAuth(auth)));
|
|
12
15
|
//#endregion
|
|
@@ -32,29 +32,33 @@ $$`,
|
|
|
32
32
|
`create trigger ${triggerName} after delete on ${sessions} referencing old table as ended for each statement execute function ${relaySchema}.session_ended()`
|
|
33
33
|
];
|
|
34
34
|
/**
|
|
35
|
-
* Refuses a sessions table the app's database does not have
|
|
36
|
-
* the
|
|
35
|
+
* Refuses a sessions table the app's database does not have, nor gets from the migration that writes the trigger
|
|
36
|
+
* after the auth store's steps (`written`): the trigger queues its job in the app's jobs queue, so the relay needs the
|
|
37
|
+
* auth store in the app's own database, as the `auth` config puts it.
|
|
37
38
|
*/
|
|
38
|
-
const refuseSessionsElsewhere = (table, sessions) => {
|
|
39
|
-
if (table) return;
|
|
39
|
+
const refuseSessionsElsewhere = (table, written, sessions) => {
|
|
40
|
+
if (table || written) return;
|
|
40
41
|
throw new Error(`The relay needs the sign-in sessions table ${sessions} in the app's own database, whose jobs queue closes ended sessions' sockets, but the app's database has no such table: keep the auth store in the app's database to use the relay.`);
|
|
41
42
|
};
|
|
42
|
-
const current = async (db, sessions) => {
|
|
43
|
+
const current = async (db, sessions, written) => {
|
|
43
44
|
const { rows } = await sql`select to_regclass(${sessions}) is not null as here, exists (
|
|
44
45
|
select from pg_trigger t join pg_proc p on p.oid = t.tgfoid
|
|
45
46
|
where t.tgrelid = to_regclass(${sessions}) and t.tgname = ${triggerName} and obj_description(p.oid, 'pg_proc') = ${sessionsComment}
|
|
46
47
|
) as found`.execute(db);
|
|
47
|
-
refuseSessionsElsewhere(rows[0].here, sessions);
|
|
48
|
+
refuseSessionsElsewhere(rows[0].here, written, sessions);
|
|
48
49
|
return rows[0].found;
|
|
49
50
|
};
|
|
50
|
-
/**
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
/**
|
|
52
|
+
* The SQL that ends deleted sessions' sockets on the relay (`sessionsSql`); `undefined` when it is current. `written`:
|
|
53
|
+
* the same migration writes the auth store's steps before it, which create the sessions table the database lacks yet.
|
|
54
|
+
*/
|
|
55
|
+
const relaySessionsMigration = async (db, sessions, written) => {
|
|
56
|
+
if (await current(db, sessions, written)) return;
|
|
53
57
|
return `${sessionsSql(sessions).join(";\n\n")};`;
|
|
54
58
|
};
|
|
55
59
|
/** Refuses to start while deleted sessions would keep their sockets on the relay. */
|
|
56
60
|
const checkRelaySessions = async (db, sessions) => {
|
|
57
|
-
if (await current(db, sessions)) return;
|
|
61
|
+
if (await current(db, sessions, false)) return;
|
|
58
62
|
throw new Error(`The trigger that closes a deleted session's sockets on the relay is missing or out of date on ${sessions}. Write it as a migration with \`${migrationCommand}\`, apply it with the project's migrations, then start again.`);
|
|
59
63
|
};
|
|
60
64
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/server",
|
|
3
|
-
"version": "0.123.
|
|
3
|
+
"version": "0.123.4",
|
|
4
4
|
"description": "The Protobase REST API as a Hono app, with Better Auth sign-in.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -44,11 +44,11 @@
|
|
|
44
44
|
"@better-auth/sso": "^1.7.12",
|
|
45
45
|
"@livekit/protocol": "1.53.1",
|
|
46
46
|
"@modelcontextprotocol/server": "^2.3.1",
|
|
47
|
-
"@protobase/layout": "0.123.
|
|
48
|
-
"@protobase/query": "0.123.
|
|
49
|
-
"@protobase/schema": "0.123.
|
|
50
|
-
"@protobase/workflow-plugins": "0.123.
|
|
51
|
-
"@protobase/workflows": "0.123.
|
|
47
|
+
"@protobase/layout": "0.123.4",
|
|
48
|
+
"@protobase/query": "0.123.4",
|
|
49
|
+
"@protobase/schema": "0.123.4",
|
|
50
|
+
"@protobase/workflow-plugins": "0.123.4",
|
|
51
|
+
"@protobase/workflows": "0.123.4",
|
|
52
52
|
"@react-email/render": "^2.1.0",
|
|
53
53
|
"@react-pdf/primitives": "^4.4.0",
|
|
54
54
|
"@react-pdf/renderer": "^4.9.0",
|