@protobase/cli 0.40.2 → 0.40.3
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { realtimeLimits } from "@protobase/server";
|
|
3
|
+
import { honorSocketMessageCaps, realtimeLimits, socketMessageCapOf } from "@protobase/server";
|
|
4
4
|
import { WebSocketServer } from "ws";
|
|
5
5
|
//#region src/project/api-websocket-server.ts
|
|
6
6
|
const require = createRequire(import.meta.url);
|
|
@@ -21,20 +21,23 @@ const maxPayloadOf = (url) => {
|
|
|
21
21
|
};
|
|
22
22
|
/**
|
|
23
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
|
|
24
|
+
* over its socket's cap (`maxPayloadOf`, or a function's lower `maxMessageBytes`) closes the socket with 1009 before it
|
|
25
|
+
* is read.
|
|
25
26
|
*/
|
|
26
27
|
const apiWebSocketServer = () => {
|
|
27
28
|
const Base = npmWebSocketServer();
|
|
28
29
|
class ApiWebSocketServer extends Base {
|
|
29
30
|
handleUpgrade(...[request, ...rest]) {
|
|
30
|
-
this.options.maxPayload = maxPayloadOf(request.url ?? "");
|
|
31
|
+
this.options.maxPayload = Math.min(maxPayloadOf(request.url ?? ""), socketMessageCapOf(request) ?? Infinity);
|
|
31
32
|
super.handleUpgrade(request, ...rest);
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
|
-
|
|
35
|
+
const server = new ApiWebSocketServer({
|
|
35
36
|
noServer: true,
|
|
36
37
|
maxPayload: realtimeLimits.maxFrameBytes
|
|
37
38
|
});
|
|
39
|
+
honorSocketMessageCaps(server);
|
|
40
|
+
return server;
|
|
38
41
|
};
|
|
39
42
|
//#endregion
|
|
40
43
|
export { apiWebSocketServer, maxPayloadOf };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.40.
|
|
3
|
+
"version": "0.40.3",
|
|
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.
|
|
40
|
-
"@protobase/query": "0.40.
|
|
41
|
-
"@protobase/schema": "0.40.
|
|
42
|
-
"@protobase/server": "0.40.
|
|
43
|
-
"@protobase/ui": "0.40.
|
|
39
|
+
"@protobase/layout": "0.40.3",
|
|
40
|
+
"@protobase/query": "0.40.3",
|
|
41
|
+
"@protobase/schema": "0.40.3",
|
|
42
|
+
"@protobase/server": "0.40.3",
|
|
43
|
+
"@protobase/ui": "0.40.3",
|
|
44
44
|
"@react-email/render": "^2.1.0",
|
|
45
45
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
46
46
|
"@tailwindcss/vite": "^4.3.3",
|
|
@@ -175,6 +175,7 @@ A client that is no browser sends `Authorization: Bearer <token>` with its upgra
|
|
|
175
175
|
| `onMessage(data, socket)` | Text arrives as a string, binary as an `ArrayBuffer`, byte for byte. Messages come one at a time and in order. |
|
|
176
176
|
| `onClose(code, reason)` | Either side closed it, after the last message. |
|
|
177
177
|
| `recheck()` | Runs every minute while the socket is open, after the framework's own check. A `401`, `403` or `404` problem it throws closes the socket with `1008`; any other error is reported and closes it with `1011`, as does a check that has not finished a minute later. What it returns is ignored, so refuse by throwing. |
|
|
178
|
+
| `maxMessageBytes` | Not an event: the largest message the socket takes, in bytes, a whole number of at least 1. A larger one closes the socket with `1009` before the server reads it, and `onMessage` never sees it. |
|
|
178
179
|
|
|
179
180
|
`socket.send(data)` takes a string, an `ArrayBuffer` or a `Uint8Array`, and `socket.close(code?, reason?)` closes it. A handler that throws closes the socket with `1011`, and the error is reported like any other.
|
|
180
181
|
|
|
@@ -280,7 +281,7 @@ The ticket only lets the socket open, and anyone who holds it may open one with
|
|
|
280
281
|
|
|
281
282
|
- **Await `send`** when the other side may read slowly: it resolves once the data is written, so a relay that awaits each send never piles up data in the server. It never rejects; after a close it resolves at once.
|
|
282
283
|
- **Return a promise from `onMessage`** to hold the next message back until it settles. Above 1 MiB of waiting messages the server stops reading from the client, which slows it down, and reads again once they are handled. Bun's built-in `ws`, which `protobase dev` uses on Bun, cannot stop reading: there the socket closes with `1013` once 16 MiB are waiting.
|
|
283
|
-
- **A message** may be up to 100 MiB.
|
|
284
|
+
- **A message** may be up to 100 MiB, or the socket's `maxMessageBytes`, which only lowers it. A larger message closes the socket with `1009` before the server reads it, so a function that only takes small messages sets it, such as `acceptWebSocket({ maxMessageBytes: 64 * 1024, onMessage })`. `protobase dev` and `protobase serve` apply it; a server of your own that hosts `createAdmin` refuses a socket with `maxMessageBytes` with a `500`, since its `ws` server would not apply it.
|
|
284
285
|
|
|
285
286
|
### Restarts
|
|
286
287
|
|