@protobase/cli 0.34.3 → 0.35.0
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/npm-ws.js +15 -0
- package/dist/build/serve-runtime.js +2 -1
- package/dist/cli/package.js +1 -1
- package/dist/dev/api-websockets.js +2 -2
- package/dist/project/api-websocket-server.js +40 -0
- package/dist/serve/lifecycle.js +2 -2
- package/package.json +6 -6
- package/skills/protobase/references/reference/custom-components.md +2 -0
- package/skills/protobase/references/reference/supabase-realtime.md +2 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
//#region src/build/npm-ws.ts
|
|
4
|
+
const require = createRequire(import.meta.url);
|
|
5
|
+
/**
|
|
6
|
+
* Bundles npm `ws` for a bare `ws` import. Built on Bun, Vite takes `ws` for a builtin and leaves it out, and the runtime
|
|
7
|
+
* then gets Bun's own shim, which realtime refuses (`apiWebSocketServer`).
|
|
8
|
+
*/
|
|
9
|
+
const npmWs = () => ({
|
|
10
|
+
name: "protobase-npm-ws",
|
|
11
|
+
enforce: "pre",
|
|
12
|
+
resolveId: (id) => id === "ws" ? path.join(path.dirname(require.resolve("ws/package.json")), "wrapper.mjs") : void 0
|
|
13
|
+
});
|
|
14
|
+
//#endregion
|
|
15
|
+
export { npmWs };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { viteBundle } from "./vite-bundle.js";
|
|
2
2
|
import { moduleFile } from "../module-file.js";
|
|
3
|
+
import { npmWs } from "./npm-ws.js";
|
|
3
4
|
import { fileURLToPath } from "node:url";
|
|
4
5
|
//#region src/build/serve-runtime.ts
|
|
5
6
|
const cliRoot = fileURLToPath(new URL("../..", import.meta.url));
|
|
@@ -10,7 +11,7 @@ const buildServeRuntime = async ({ outFile, bun }) => {
|
|
|
10
11
|
entry: serveMain,
|
|
11
12
|
outFile,
|
|
12
13
|
bun,
|
|
13
|
-
plugins: []
|
|
14
|
+
plugins: [npmWs()]
|
|
14
15
|
});
|
|
15
16
|
};
|
|
16
17
|
//#endregion
|
package/dist/cli/package.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { apiWebSocketServer } from "../project/api-websocket-server.js";
|
|
1
2
|
import { isAllowedHost } from "./allowed-host.js";
|
|
2
3
|
import { isProjectFile } from "./project-files.js";
|
|
3
4
|
import { createAdaptorServer } from "@hono/node-server";
|
|
4
|
-
import { WebSocketServer } from "ws";
|
|
5
5
|
//#region src/dev/api-websockets.ts
|
|
6
6
|
const isApiWebSocket = (url) => /^\/api\/sb\/realtime\/v1\/websocket(\?|$)/.test(url) || /^\/api\/functions\/[^/?#]+(\/|\?|$)/.test(url);
|
|
7
7
|
const restartCode = 1012;
|
|
@@ -15,7 +15,7 @@ const apiUpgrades = (allowedHosts, forward) => (request, socket, head) => {
|
|
|
15
15
|
socket.end("HTTP/1.1 403 Forbidden\r\nConnection: close\r\nContent-Length: 0\r\n\r\n");
|
|
16
16
|
};
|
|
17
17
|
const apiWebSockets = (entry, dirs) => {
|
|
18
|
-
const wss =
|
|
18
|
+
const wss = apiWebSocketServer();
|
|
19
19
|
return {
|
|
20
20
|
name: "protobase-api-websockets",
|
|
21
21
|
configureServer: (server) => {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { realtimeLimits } from "@protobase/server";
|
|
4
|
+
import { WebSocketServer } from "ws";
|
|
5
|
+
//#region src/project/api-websocket-server.ts
|
|
6
|
+
const require = createRequire(import.meta.url);
|
|
7
|
+
const npmWebSocketServer = () => {
|
|
8
|
+
if (process.versions.bun === void 0 || WebSocketServer !== require("ws").WebSocketServer) return WebSocketServer;
|
|
9
|
+
return require(path.join(path.dirname(require.resolve("ws/package.json")), "index.js")).WebSocketServer;
|
|
10
|
+
};
|
|
11
|
+
const functionsPrefix = "/api/functions/";
|
|
12
|
+
const functionMaxPayload = 104857600;
|
|
13
|
+
/**
|
|
14
|
+
* The frame cap of a socket upgraded at `url`: ws's default for an api function's socket, and realtime's
|
|
15
|
+
* `maxFrameBytes` for any other, so a path this does not recognise as a function's, such as an encoded one, gets the
|
|
16
|
+
* smaller cap.
|
|
17
|
+
*/
|
|
18
|
+
const maxPayloadOf = (url) => {
|
|
19
|
+
if (!URL.canParse(url, "http://localhost")) return realtimeLimits.maxFrameBytes;
|
|
20
|
+
return new URL(url, "http://localhost").pathname.startsWith(functionsPrefix) ? functionMaxPayload : realtimeLimits.maxFrameBytes;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* The server of npm `ws` that upgrades the API's sockets, realtime's and the app's functions', on Node and Bun: a frame
|
|
24
|
+
* over its socket's cap (`maxPayloadOf`) closes the socket with 1009 before it is read.
|
|
25
|
+
*/
|
|
26
|
+
const apiWebSocketServer = () => {
|
|
27
|
+
const Base = npmWebSocketServer();
|
|
28
|
+
class ApiWebSocketServer extends Base {
|
|
29
|
+
handleUpgrade(...[request, ...rest]) {
|
|
30
|
+
this.options.maxPayload = maxPayloadOf(request.url ?? "");
|
|
31
|
+
super.handleUpgrade(request, ...rest);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return new ApiWebSocketServer({
|
|
35
|
+
noServer: true,
|
|
36
|
+
maxPayload: realtimeLimits.maxFrameBytes
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
//#endregion
|
|
40
|
+
export { apiWebSocketServer, maxPayloadOf };
|
package/dist/serve/lifecycle.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { apiWebSocketServer } from "../project/api-websocket-server.js";
|
|
1
2
|
import { withClientAddress } from "./client-address.js";
|
|
2
3
|
import { projectAdmin } from "../project/project-admin.js";
|
|
3
4
|
import { createPgDb } from "../project/pg-db.js";
|
|
@@ -6,7 +7,6 @@ import { startCleanupTimer } from "./cleanup-timer.js";
|
|
|
6
7
|
import { closeSockets } from "./close-sockets.js";
|
|
7
8
|
import { backgroundSettled, checkAi, checkAuthSchema, checkChanges, checkComments, checkComputed, checkJobsSchema, checkWebhooksSchema, configExports, createFileCleanup, startJobs } from "@protobase/server";
|
|
8
9
|
import { createAdaptorServer, upgradeWebSocket } from "@hono/node-server";
|
|
9
|
-
import { WebSocketServer } from "ws";
|
|
10
10
|
import pg from "pg";
|
|
11
11
|
//#region src/serve/lifecycle.ts
|
|
12
12
|
const listen = (server, port) => new Promise((resolve, reject) => {
|
|
@@ -49,7 +49,7 @@ const startServe = async ({ project, env, createDb = (url) => createPgDb(pg, url
|
|
|
49
49
|
...jobs && { jobs },
|
|
50
50
|
...env.drainToken && { drainToken: env.drainToken }
|
|
51
51
|
});
|
|
52
|
-
const sockets =
|
|
52
|
+
const sockets = apiWebSocketServer();
|
|
53
53
|
const server = createAdaptorServer({
|
|
54
54
|
fetch: withClientAddress(app.fetch, env.trustedProxies),
|
|
55
55
|
overrideGlobalObjects: false,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.35.0",
|
|
4
4
|
"description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
"@better-auth/core": "^1.7.12",
|
|
37
37
|
"@hono/node-server": "^2.1.3",
|
|
38
38
|
"@hono/vite-dev-server": "^0.26.1",
|
|
39
|
-
"@protobase/layout": "0.
|
|
40
|
-
"@protobase/query": "0.
|
|
41
|
-
"@protobase/schema": "0.
|
|
42
|
-
"@protobase/server": "0.
|
|
43
|
-
"@protobase/ui": "0.
|
|
39
|
+
"@protobase/layout": "0.35.0",
|
|
40
|
+
"@protobase/query": "0.35.0",
|
|
41
|
+
"@protobase/schema": "0.35.0",
|
|
42
|
+
"@protobase/server": "0.35.0",
|
|
43
|
+
"@protobase/ui": "0.35.0",
|
|
44
44
|
"@react-email/render": "^2.1.0",
|
|
45
45
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
46
46
|
"@tailwindcss/vite": "^4.3.3",
|
|
@@ -71,6 +71,8 @@ The element stays data, `{ type: 'OrdersPerDay', props: { days: 30 }, children:
|
|
|
71
71
|
|
|
72
72
|
A component that asks for a one-time code uses `OtpInput` from `@protobase/ui`, the field of the app's own code pages: a box per digit drawn over one real input, so pasting a whole code into any box, the system's code autofill from a mail or a text message, and the phone's digit keyboard all work. It takes `value` and `onChange`, `length` (6 by default), `invalid` and `disabled`, and `onComplete` gets the code once its last digit is in, to check it at once. Ask for a code on a step of its own, before anything else.
|
|
73
73
|
|
|
74
|
+
A component that shows markdown, such as a chat message, uses `Markdown` from `@protobase/ui`, which markdown fields draw with: `source` is the markdown, in GitHub's flavour with line breaks kept, shown in the theme's styles. Raw HTML in it shows as text, links open in a new tab, and only links and images to web, mail and phone addresses or relative ones stay. `className` adds classes to its outer element, and `inLink` draws it as running text inside a link, such as a card, with its links and images as their text.
|
|
75
|
+
|
|
74
76
|
`protobase build` fails when the config declares a component that `protobase.ui.tsx` does not export, naming it; while you work, `protobase dev` draws a warning in its place. A component a plugin provides is declared with the plugin's name, `component('DraftOrders', { plugin: 'sales-tools' })`, and the build does not look for it in `protobase.ui.tsx`. A component that throws while drawing shows a warning in its own place, not a blank app. The object form, `defineUi({ components: { OrdersPerDay } })`, still works, and a name given both ways must be the same component.
|
|
75
77
|
|
|
76
78
|
### Fields and resources in props
|
|
@@ -44,6 +44,8 @@ room
|
|
|
44
44
|
|
|
45
45
|
A broadcast reaches the topic's other channels, and the sender's own with `self`; with `ack`, `send` resolves once the server has it. Binary payloads go to clients on the default serializer (`vsn` 2.0.0) only. Presence follows Phoenix Presence: a channel tracks one presence under its `presence.key` (a random one when it names none), tracking again replaces it, and channels with presence enabled get the state when they join and each join and leave after, their own included. A channel that leaves, closes or whose token expires leaves the presence it tracked.
|
|
46
46
|
|
|
47
|
+
Limits, near Supabase's Free plan, apply per socket and per topic. A socket sends at most 100 broadcast and presence messages a second, joins at most 100 times a second and holds at most 100 channels; on each channel it sends at most 5 presence updates in 30 seconds, also counted across a rejoin. A topic takes 100 broadcasts a second, whoever sends them, so one busy sender can use up a topic's budget. A topic is at most 255 bytes, and a tracked presence at most 10 000 bytes of JSON. A message over a limit gets an error reply and goes to no one, where Supabase would close the channel. A frame over 256 KiB closes the socket with 1009. It closes with 1008 when the client leaves more than 4 MiB unread, or sends more than 300 messages or 4 MiB while earlier ones wait, such as behind a token check.
|
|
48
|
+
|
|
47
49
|
Broadcasts and presence go between the channels of one serving process, which is how a cloud app runs; several processes behind one address do not reach each other's channels. Sending without a joined channel, which supabase-js does over `POST /api/sb/realtime/v1/api/broadcast`, is not supported.
|
|
48
50
|
|
|
49
51
|
## What a subscriber receives
|