@protobase/cli 0.26.4 → 0.26.6
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/dev/api-websockets.js +28 -0
- package/dist/dev/entry.js +2 -1
- package/dist/dev/project-files.js +5 -0
- package/dist/dev/run.js +7 -3
- package/dist/package.js +1 -1
- package/dist/serve/host-modules.js +1 -1
- package/dist/serve/lifecycle.js +1 -1
- package/package.json +6 -6
- package/skills/protobase/references/reference/api.md +2 -2
- package/skills/protobase/references/reference/cli.md +1 -1
- package/skills/protobase/references/reference/supabase-realtime.md +1 -1
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { isProjectFile } from "./project-files.js";
|
|
2
|
+
import { createAdaptorServer } from "@hono/node-server";
|
|
3
|
+
import { WebSocketServer } from "ws";
|
|
4
|
+
//#region src/dev/api-websockets.ts
|
|
5
|
+
const isApiWebSocket = (url) => /^\/realtime\/v1\/websocket(\?|$)/.test(url);
|
|
6
|
+
const restartCode = 1012;
|
|
7
|
+
const apiWebSockets = (entry, dirs) => {
|
|
8
|
+
const wss = new WebSocketServer({ noServer: true });
|
|
9
|
+
return {
|
|
10
|
+
name: "protobase-api-websockets",
|
|
11
|
+
configureServer: (server) => {
|
|
12
|
+
const upgrades = createAdaptorServer({
|
|
13
|
+
fetch: async (request, env) => (await server.ssrLoadModule(entry)).default.fetch(request, env),
|
|
14
|
+
overrideGlobalObjects: false,
|
|
15
|
+
websocket: { server: wss }
|
|
16
|
+
});
|
|
17
|
+
server.httpServer?.on("upgrade", (request, socket, head) => {
|
|
18
|
+
if (isApiWebSocket(request.url ?? "")) upgrades.emit("upgrade", request, socket, head);
|
|
19
|
+
});
|
|
20
|
+
server.httpServer?.on("close", () => upgrades.emit("close"));
|
|
21
|
+
},
|
|
22
|
+
handleHotUpdate: ({ file }) => {
|
|
23
|
+
if (isProjectFile(dirs, file)) wss.clients.forEach((client) => client.close(restartCode));
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
//#endregion
|
|
28
|
+
export { apiWebSockets, isApiWebSocket };
|
package/dist/dev/entry.js
CHANGED
|
@@ -3,6 +3,7 @@ import { projectErrorReporter } from "../project/error-reporter.js";
|
|
|
3
3
|
import { projectAdmin } from "../project/project-admin.js";
|
|
4
4
|
import { loadProject, projectDb } from "./project.js";
|
|
5
5
|
import { checkAi, checkAuthSchema, checkChanges, checkComments, checkComputed, checkWebhooksSchema, configExports, hasUsers } from "@protobase/server";
|
|
6
|
+
import { upgradeWebSocket } from "@hono/node-server";
|
|
6
7
|
import { Hono } from "hono";
|
|
7
8
|
//#region src/dev/entry.ts
|
|
8
9
|
const projectDir = process.env.PROTOBASE_PROJECT;
|
|
@@ -29,7 +30,7 @@ const reporter = await projectErrorReporter(project, process.env);
|
|
|
29
30
|
const { admin, jobs } = projectAdmin({
|
|
30
31
|
...project,
|
|
31
32
|
authenticate: project.authenticate
|
|
32
|
-
}, project.exports, db, void 0, reporter);
|
|
33
|
+
}, project.exports, db, void 0, reporter, upgradeWebSocket);
|
|
33
34
|
await devJobs(db, jobs);
|
|
34
35
|
var entry_default = new Hono().route("/", admin);
|
|
35
36
|
if (project.auth && !store.__protobaseNoUsersShown) {
|
package/dist/dev/run.js
CHANGED
|
@@ -9,6 +9,8 @@ import { faviconLink } from "../project/favicon-link.js";
|
|
|
9
9
|
import { themeLink } from "../project/theme-link.js";
|
|
10
10
|
import { checkDatabase } from "./check-database.js";
|
|
11
11
|
import { stopDevJobs } from "./dev-jobs.js";
|
|
12
|
+
import { isProjectFile } from "./project-files.js";
|
|
13
|
+
import { apiWebSockets } from "./api-websockets.js";
|
|
12
14
|
import { existsSync } from "node:fs";
|
|
13
15
|
import path from "node:path";
|
|
14
16
|
import { createServer, searchForWorkspaceRoot } from "vite";
|
|
@@ -24,7 +26,7 @@ const requireAppFiles = (appDir) => {
|
|
|
24
26
|
const reloadOnProjectChange = (dirs) => ({
|
|
25
27
|
name: "protobase-project-reload",
|
|
26
28
|
handleHotUpdate: ({ file, server }) => {
|
|
27
|
-
if (dirs
|
|
29
|
+
if (isProjectFile(dirs, file)) server.environments.ssr.moduleGraph.invalidateAll();
|
|
28
30
|
}
|
|
29
31
|
});
|
|
30
32
|
const stopJobsOnClose = {
|
|
@@ -56,6 +58,7 @@ const runDev = async (options, out) => {
|
|
|
56
58
|
requireAppFiles(appDir);
|
|
57
59
|
await checkDatabase(url, options.projectDir);
|
|
58
60
|
const extensions = options.extensions ?? [];
|
|
61
|
+
const projectDirs = [options.projectDir, ...extensions.map((extension) => extension.dir)];
|
|
59
62
|
process.env.PROTOBASE_PROJECT = options.projectDir;
|
|
60
63
|
process.env.PROTOBASE_EXTENSIONS = JSON.stringify(extensions);
|
|
61
64
|
process.env.PROTOBASE_DATABASE_URL = url;
|
|
@@ -79,7 +82,8 @@ const runDev = async (options, out) => {
|
|
|
79
82
|
] }
|
|
80
83
|
},
|
|
81
84
|
plugins: [
|
|
82
|
-
reloadOnProjectChange(
|
|
85
|
+
reloadOnProjectChange(projectDirs),
|
|
86
|
+
apiWebSockets(entry, projectDirs),
|
|
83
87
|
stopJobsOnClose,
|
|
84
88
|
sharedModulesPlugin(),
|
|
85
89
|
themeLink(options.projectDir),
|
|
@@ -92,7 +96,7 @@ const runDev = async (options, out) => {
|
|
|
92
96
|
tailwindcss(),
|
|
93
97
|
devServer({
|
|
94
98
|
entry,
|
|
95
|
-
exclude: [/^(?!\/api(\/|\?|$)|\/\.well-known\/webauthn(\?|$)).*/],
|
|
99
|
+
exclude: [/^(?!\/(api|auth\/v1|realtime\/v1)(\/|\?|$)|\/\.well-known\/webauthn(\?|$)).*/],
|
|
96
100
|
injectClientScript: false
|
|
97
101
|
})
|
|
98
102
|
]
|
package/dist/package.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as server from "@protobase/server";
|
|
2
2
|
import * as postgres$1 from "postgres";
|
|
3
|
+
import * as nodeServer from "@hono/node-server";
|
|
3
4
|
import * as query from "@protobase/query";
|
|
4
5
|
import * as kysely from "kysely";
|
|
5
6
|
import * as pg$1 from "pg";
|
|
6
7
|
import * as schema from "@protobase/schema";
|
|
7
8
|
import * as layout from "@protobase/layout";
|
|
8
|
-
import * as nodeServer from "@hono/node-server";
|
|
9
9
|
import * as hono from "hono";
|
|
10
10
|
import * as reactEmailRender from "@react-email/render";
|
|
11
11
|
import * as apiReference from "@scalar/hono-api-reference";
|
package/dist/serve/lifecycle.js
CHANGED
|
@@ -3,9 +3,9 @@ import { createPgDb } from "../project/pg-db.js";
|
|
|
3
3
|
import { createServeApp } from "./app.js";
|
|
4
4
|
import { startCleanupTimer } from "./cleanup-timer.js";
|
|
5
5
|
import { checkAi, checkAuthSchema, checkChanges, checkComments, checkComputed, checkJobsSchema, checkWebhooksSchema, configExports, createFileCleanup, startJobs } from "@protobase/server";
|
|
6
|
-
import pg from "pg";
|
|
7
6
|
import { createAdaptorServer, upgradeWebSocket } from "@hono/node-server";
|
|
8
7
|
import { WebSocketServer } from "ws";
|
|
8
|
+
import pg from "pg";
|
|
9
9
|
//#region src/serve/lifecycle.ts
|
|
10
10
|
const listen = (server, port) => new Promise((resolve, reject) => {
|
|
11
11
|
server.once("error", reject);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.26.
|
|
3
|
+
"version": "0.26.6",
|
|
4
4
|
"description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -35,11 +35,11 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@hono/node-server": "^2.1.3",
|
|
37
37
|
"@hono/vite-dev-server": "^0.26.1",
|
|
38
|
-
"@protobase/layout": "0.26.
|
|
39
|
-
"@protobase/query": "0.26.
|
|
40
|
-
"@protobase/schema": "0.26.
|
|
41
|
-
"@protobase/server": "0.26.
|
|
42
|
-
"@protobase/ui": "0.26.
|
|
38
|
+
"@protobase/layout": "0.26.6",
|
|
39
|
+
"@protobase/query": "0.26.6",
|
|
40
|
+
"@protobase/schema": "0.26.6",
|
|
41
|
+
"@protobase/server": "0.26.6",
|
|
42
|
+
"@protobase/ui": "0.26.6",
|
|
43
43
|
"@react-email/render": "^2.1.0",
|
|
44
44
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
45
45
|
"@tailwindcss/vite": "^4.3.3",
|
|
@@ -186,9 +186,9 @@ Real login is [Better Auth](auth.md)). Lower level:
|
|
|
186
186
|
|
|
187
187
|
The API sends no CORS headers until it has something to allow: other websites in `options.cors` (a list of origins, or `'*'` for any), which defaults to `PROTOBASE_CORS_ORIGINS` (`*` or comma separated origins), or other [origins of the app](auth.md#several-origins)), which are always allowed.
|
|
188
188
|
|
|
189
|
-
- It covers `/api/*` but Better Auth's `/api/auth/*`, which checks origins itself, and [API functions](../guides/api-functions.md)) with a `cors` of their own.
|
|
189
|
+
- It covers `/api/*` but Better Auth's `/api/auth/*`, which checks origins itself, and [API functions](../guides/api-functions.md)) with a `cors` of their own, and supabase-js's sign-in at [`/auth/v1`](auth.md#supabase-js-and-supabasessr)).
|
|
190
190
|
- An allowed origin gets `Access-Control-Allow-Origin` with its name and `Vary: Origin`, or `*` with `'*'`. No credentials: browser code calls the API with a bearer token.
|
|
191
|
-
- Preflights are answered before authentication, for `authorization`, `content-type`, `if-match
|
|
191
|
+
- Preflights are answered before authentication, for `authorization`, `content-type`, `if-match`, `if-none-match` and supabase-js's `apikey`, `x-client-info` and `x-supabase-api-version`, and kept for 10 minutes. `Location`, `ETag`, `X-Meta-Version` and `X-Protobase-Warning` are exposed.
|
|
192
192
|
- An API whose resources another app draws as [remote resources](remote-resources.md#cors)) lists that app's origin here.
|
|
193
193
|
|
|
194
194
|
## Safety
|
|
@@ -101,7 +101,7 @@ Exit code is 1 when there are errors. Run it after the project's migrations and
|
|
|
101
101
|
protobase dev [--port 5173] [--env DATABASE_URL] [--cache-dir <dir>] [--allowed-hosts <hosts>] [--extend <dir>] # run inside a project, e.g. bun run --cwd examples/erp dev
|
|
102
102
|
```
|
|
103
103
|
|
|
104
|
-
One process, one port: Vite serves the admin app from `@protobase/ui`'s `src/app/` (`dist/app/` when installed; `index.html` and `main.tsx`, or `main.js`; the command fails with a clear message when they are missing) and `@hono/vite-dev-server` mounts the Hono app from `createAdmin` under `/api`. Open `http://localhost:<port>`; the API reference is at `/api/docs`.
|
|
104
|
+
One process, one port: Vite serves the admin app from `@protobase/ui`'s `src/app/` (`dist/app/` when installed; `index.html` and `main.tsx`, or `main.js`; the command fails with a clear message when they are missing) and `@hono/vite-dev-server` mounts the Hono app from `createAdmin` under `/api`, with supabase-js's `/auth/v1` and `/realtime/v1`. Open `http://localhost:<port>`; the API reference is at `/api/docs`.
|
|
105
105
|
|
|
106
106
|
- **Database:** the URL comes from the variable named by `--env`, read from the environment or the nearest `.env` at or above the project. The connection is checked before anything starts; if it fails, the command names host, port and reason (and points to its `db:up` script when it has one). The project needs `pg` installed, because the API connects with Kysely over the project's own `pg`.
|
|
107
107
|
- **Cache:** Vite's dependency cache is `node_modules/.vite`; two dev servers sharing it can disturb each other's optimisation, so pass `--cache-dir` for a second one (the integration test does).
|
|
@@ -20,7 +20,7 @@ supabase
|
|
|
20
20
|
|
|
21
21
|
The keys are `options.apiKeys` of `createAdmin`, `{ publishable_key, secret_key }`, or else `PROTOBASE_PUBLISHABLE_KEY` and `PROTOBASE_SECRET_KEY`. The socket sends the key in its URL and is refused with `401` without a key of the app. Each channel joins with the client's access token: a signed-in user's token makes it `authenticated` with the token's claims, the publishable key alone `anon`, the secret key alone the app's own role. A token the client refreshes on an open socket replaces the channel's; a channel whose token expires is closed with a `Token has expired` system message, as on Supabase.
|
|
22
22
|
|
|
23
|
-
The server serves the socket when the host gives `createAdmin` its WebSocket upgrade: `protobase serve` does, on Bun and Node. `protobase dev`
|
|
23
|
+
The server serves the socket when the host gives `createAdmin` its WebSocket upgrade: `protobase serve` does, on Bun and Node, and so does `protobase dev`, beside Vite's hot reload socket. An edit to the project under `protobase dev` closes the open sockets with code `1012`, and supabase-js reconnects to the rebuilt API.
|
|
24
24
|
|
|
25
25
|
## Which tables
|
|
26
26
|
|