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/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
- * Create crossws-compatible hooks for Silgi RPC over WebSocket.
20
+ * Internal — build crossws-compatible hooks for Silgi RPC over WebSocket.
21
21
  *
22
- * Works with any crossws integration Nitro, Deno, Bun, Cloudflare, etc.
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
- function createWSHooks(routerDef, options = {}) {
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 || !route.ws) {
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: createWSHooks(routerDef, options),
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 { attachWebSocket, createWSHooks };
195
+ export { _createWSHooks, attachWebSocket };