silgi 0.50.1 → 0.50.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/adapters/_fetch-adapter.d.mts +4 -2
- package/dist/adapters/_fetch-adapter.mjs +4 -4
- package/dist/client/adapters/websocket/index.d.mts +2 -2
- package/dist/client/adapters/websocket/index.mjs +146 -15
- package/dist/compile.d.mts +0 -2
- package/dist/compile.mjs +0 -1
- package/dist/core/handler.d.mts +7 -1
- package/dist/core/handler.mjs +30 -1
- package/dist/core/serve.d.mts +7 -2
- package/dist/core/serve.mjs +54 -21
- package/dist/index.d.mts +1 -1
- package/dist/plugins/file-upload.d.mts +1 -1
- package/dist/scalar.mjs +2 -2
- package/dist/silgi.d.mts +1 -1
- package/dist/silgi.mjs +23 -23
- package/dist/types.d.mts +0 -2
- package/dist/ws.d.mts +6 -16
- package/dist/ws.mjs +8 -18
- package/lib/dashboard/index.html +50 -50
- package/package.json +1 -1
package/dist/ws.mjs
CHANGED
|
@@ -17,23 +17,13 @@ import { decode, encode } from "./codec/msgpack.mjs";
|
|
|
17
17
|
const peerAbortControllers = /* @__PURE__ */ new WeakMap();
|
|
18
18
|
const peerKeepaliveTimers = /* @__PURE__ */ new WeakMap();
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
20
|
+
* Internal — build crossws-compatible hooks for Silgi RPC over WebSocket.
|
|
21
21
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```ts
|
|
26
|
-
* // Nitro / Nuxt
|
|
27
|
-
* import { createWSHooks } from "silgi/ws";
|
|
28
|
-
* export default defineWebSocketHandler(createWSHooks(appRouter));
|
|
29
|
-
*
|
|
30
|
-
* // With context
|
|
31
|
-
* export default defineWebSocketHandler(createWSHooks(appRouter, {
|
|
32
|
-
* context: (peer) => ({ userId: peer.request?.headers.get('x-user-id') }),
|
|
33
|
-
* }));
|
|
34
|
-
* ```
|
|
22
|
+
* Used by `attachWebSocket()`, `serve({ ws: true })`, and `handler()` auto-WS.
|
|
23
|
+
* Not part of the public API; callers should use one of those higher-level entry points.
|
|
35
24
|
*/
|
|
36
|
-
|
|
25
|
+
/** @internal — exported only for use by silgi.ts handler() and attachWebSocket(). Not part of the public API. */
|
|
26
|
+
function _createWSHooks(routerDef, options = {}) {
|
|
37
27
|
const flat = compileRouter(routerDef);
|
|
38
28
|
const useMsgpack = options.protocol === "messagepack" || options.protocol == null && (options.binary ?? false);
|
|
39
29
|
const contextFactory = options.context;
|
|
@@ -87,7 +77,7 @@ function createWSHooks(routerDef, options = {}) {
|
|
|
87
77
|
}
|
|
88
78
|
const { id, path, input } = req;
|
|
89
79
|
const route = flat("POST", "/" + path)?.data;
|
|
90
|
-
if (!route
|
|
80
|
+
if (!route) {
|
|
91
81
|
send(peer, {
|
|
92
82
|
id,
|
|
93
83
|
error: {
|
|
@@ -194,7 +184,7 @@ async function attachWebSocket(server, routerDef, options = {}) {
|
|
|
194
184
|
if (options.compress) serverOptions.perMessageDeflate = typeof options.compress === "object" ? options.compress : true;
|
|
195
185
|
if (options.maxPayload !== void 0) serverOptions.maxPayload = options.maxPayload;
|
|
196
186
|
const ws = nodeAdapter({
|
|
197
|
-
hooks:
|
|
187
|
+
hooks: _createWSHooks(routerDef, options),
|
|
198
188
|
...Object.keys(serverOptions).length > 0 && { serverOptions }
|
|
199
189
|
});
|
|
200
190
|
server.on("upgrade", (req, socket, head) => {
|
|
@@ -202,4 +192,4 @@ async function attachWebSocket(server, routerDef, options = {}) {
|
|
|
202
192
|
});
|
|
203
193
|
}
|
|
204
194
|
//#endregion
|
|
205
|
-
export {
|
|
195
|
+
export { _createWSHooks, attachWebSocket };
|